ZQuest Classic Coverage Report


Directory: src/
File: src/zq/zquest.cpp
Date: 2025-11-05 06:08:28
Exec Total Coverage
Lines: 2262 15457 14.6%
Functions: 49 744 6.6%
Branches: 1398 12267 11.4%

Line Branch Exec Source
1 #include "allegro/gui.h"
2 #include "base/files.h"
3 #include "base/mapscr.h"
4 #include "dialog/edit_region.h"
5
6 #include <memory>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <cstring>
10 #include <sstream>
11 #include <ctype.h>
12 #include <assert.h>
13 #include <time.h>
14 #include <vector>
15 #include <filesystem>
16 #include <base/new_menu.h>
17
18 #include "dialog/info_lister.h"
19 #ifdef __APPLE__
20 // malloc.h is deprecated, but malloc also lives in stdlib
21 #include <stdlib.h>
22 #else
23 #include <malloc.h>
24 #endif
25
26 #include "zalleg/zalleg.h"
27 #include "base/qrs.h"
28 #include "base/dmap.h"
29 #include "base/msgstr.h"
30 #include "base/packfile.h"
31 #include "base/cpool.h"
32 #include "base/autocombo.h"
33 #include "base/render.h"
34 #include "base/version.h"
35 #include "zq/autocombo/autopattern_base.h"
36 #include "zq/autocombo/pattern_basic.h"
37 #include "zq/autocombo/pattern_flatmtn.h"
38 #include "zq/autocombo/pattern_fence.h"
39 #include "zq/autocombo/pattern_cakemtn.h"
40 #include "zq/autocombo/pattern_relational.h"
41 #include "zq/autocombo/pattern_dungeoncarve.h"
42 #include "zq/autocombo/pattern_dormtn.h"
43 #include "zq/autocombo/pattern_tiling.h"
44 #include "zq/autocombo/pattern_replace.h"
45 #include "zq/autocombo/pattern_denseforest.h"
46 #include "zq/autocombo/pattern_extend.h"
47 #include "zq/render_hotkeys.h"
48 #include "zq/render_minimap.h"
49 #include "zq/render_tooltip.h"
50 #include "base/misctypes.h"
51 #include "parser/Compiler.h"
52 #include "base/zc_alleg.h"
53 #include "particles.h"
54 #include "dialog/combopool.h"
55 #include "dialog/alert.h"
56 #include "dialog/alertfunc.h"
57 #include "zq/gui/edit_autocombo.h"
58
59 #include <al5_img.h>
60 #include <loadpng.h>
61 #include <fmt/format.h>
62
63 #include "dialog/cheat_codes.h"
64 #include "dialog/set_password.h"
65 #include "dialog/foodlg.h"
66 #include "dialog/quest_rules.h"
67 #include "dialog/script_rules.h"
68 #include "dialog/headerdlg.h"
69 #include "dialog/ffc_editor.h"
70 #include "dialog/screen_data.h"
71 #include "dialog/edit_dmap.h"
72 #include "dialog/compilezscript.h"
73 #include "dialog/screen_enemies.h"
74 #include "dialog/enemypattern.h"
75 #include "dialog/sfxdata.h"
76 #include "dialog/mapstyles.h"
77 #include "dialog/externs.h"
78
79 #include "base/gui.h"
80 #include "gui/jwin_a5.h"
81 #include "gui/jwin.h"
82 #include "zc_list_data.h"
83 #include "gui/editbox.h"
84 #include "zq/zq_misc.h"
85 #include "zq/zq_tiles.h" // tile and combo code
86
87 #include "zq/zquest.h"
88 #include "zq/ffasm.h"
89 #include "zq/render.h"
90
91 // the following are used by both zelda.cc and zquest.cc
92 #include "base/zdefs.h"
93 #include "base/qrs.h"
94 #include "tiles.h"
95 #include "base/colors.h"
96 #include "base/qst.h"
97 #include "base/zsys.h"
98 #include "base/zapp.h"
99 #include "base/process_management.h"
100 #include "play_midi.h"
101 #include "sound/zcmusic.h"
102
103 #include "midi.h"
104 #include "sprite.h"
105 #include "fontsdat.h"
106 #include "base/jwinfsel.h"
107 #include "zq/zq_class.h"
108 #include "subscr.h"
109 #include "zq/zq_subscr.h"
110 #include "zc/ffscript.h"
111 #include "gui/EditboxNew.h"
112 #include "sfx.h"
113 #include "zq/zq_custom.h" // custom items and guys
114 #include "zq/zq_strings.h"
115 #include "zq/questReport.h"
116 #include <fstream>
117 #include "drawing.h"
118 #include "zconsole/ConsoleLogger.h"
119 #include "colorname.h"
120 #include "zq/zq_hotkey.h"
121 #include "zq/package.h"
122 #include "zq/zq_files.h"
123 #include "music_playback.h"
124
125 //Windows mmemory tools
126 #ifdef _WIN32
127 #include <windows.h>
128 #include <stdio.h>
129 #include <psapi.h>
130 #pragma comment(lib, "psapi.lib") // Needed to avoid linker issues. -Z
131 #endif
132
133 #ifdef __EMSCRIPTEN__
134 #include <emscripten/emscripten.h>
135 #endif
136
137 #define MIDI_TRACK_BUFFER_SIZE 50
138 extern CConsoleLoggerEx parser_console;
139
140 using ZScript::disassembled_script_data;
141 void write_script(vector<shared_ptr<ZScript::Opcode>> const& zasm, string& dest,
142 bool commented, map<string,disassembled_script_data>* scr_meta_map);
143
144 namespace fs = std::filesystem;
145
146 #if defined(ALLEGRO_WINDOWS)
147 static const char *data_path_name = "win_data_path";
148 static const char *midi_path_name = "win_midi_path";
149 static const char *image_path_name = "win_image_path";
150 static const char *tmusic_path_name = "win_tmusic_path";
151 static const char *last_quest_name = "win_last_quest";
152 static const char *qtname_name = "win_qtname%d";
153 static const char *qtpath_name = "win_qtpath%d";
154 #elif defined(ALLEGRO_LINUX)
155 static const char *data_path_name = "linux_data_path";
156 static const char *midi_path_name = "linux_midi_path";
157 static const char *image_path_name = "linux_image_path";
158 static const char *tmusic_path_name = "linux_tmusic_path";
159 static const char *last_quest_name = "linux_last_quest";
160 static const char *qtname_name = "linux_qtname%d";
161 static const char *qtpath_name = "linux_qtpath%d";
162 #elif defined(__APPLE__)
163 static const char *data_path_name = "macosx_data_path";
164 static const char *midi_path_name = "macosx_midi_path";
165 static const char *image_path_name = "macosx_image_path";
166 static const char *tmusic_path_name = "macosx_tmusic_path";
167 static const char *last_quest_name = "macosx_last_quest";
168 static const char *qtname_name = "macosx_qtname%d";
169 static const char *qtpath_name = "macosx_qtpath%d";
170 #endif
171
172 #include "base/win32.h"
173
174 #include "zq/zq_init.h"
175 #include "zq/zq_doors.h"
176 #include "zq/zq_cset.h"
177 #include "zinfo.h"
178
179 #ifdef _MSC_VER
180 #include <crtdbg.h>
181
182 #endif
183
184 // MSVC fix
185 #if _MSC_VER >= 1900
186 FILE _iob[] = { *stdin, *stdout, *stderr };
187 extern "C" FILE * __cdecl __iob_func(void) { return _iob; }
188 #endif
189
190 extern byte monochrome_console;
191
192 #include "zconsole/ConsoleLogger.h"
193
194 extern CConsoleLoggerEx zscript_coloured_console;
195
196 uint8_t console_is_open = 0;
197 bool is_zq_replay_test = false;
198
199 #include "base/util.h"
200
201 #ifdef __EMSCRIPTEN__
202 #include "base/emscripten_utils.h"
203 #endif
204
205 using namespace util;
206
207 using std::vector;
208 using std::map;
209 using std::stringstream;
210
211 12 FFScript FFCore;
212
213 void load_size_poses();
214 void do_previewtext();
215 bool do_slots(vector<shared_ptr<ZScript::Opcode>> const& zasm,
216 map<string, disassembled_script_data> &scripts, int assign_mode);
217
218 int32_t startdmapxy[6] = {-1000, -1000, -1000, -1000, -1000, -1000};
219 bool cancelgetnum=false;
220
221 int32_t tooltip_timer=0, tooltip_maxtimer=30, tooltip_current_ffc=0;
222 int32_t combobrushoverride=-1;
223 ComboPosition mouse_combo_pos;
224
225 int32_t original_playing_field_offset=0;
226 12 int32_t playing_field_offset=original_playing_field_offset;
227 int32_t passive_subscreen_height=56;
228
229 bool disable_saving=false, OverwriteProtection;
230 bool halt=false;
231 bool show_sprites=true;
232 bool show_hitboxes = false;
233 bool zq_ignore_item_ownership = true;
234
235 // Used to find FFC script names
236 vector<string> asffcscripts;
237 vector<string> asglobalscripts;
238 vector<string> asitemscripts;
239 vector<string> asnpcscripts;
240 vector<string> aseweaponscripts;
241 vector<string> aslweaponscripts;
242 vector<string> asplayerscripts;
243 vector<string> asdmapscripts;
244 vector<string> asscreenscripts;
245 vector<string> asitemspritescripts;
246 vector<string> ascomboscripts;
247 vector<string> asgenericscripts;
248 vector<string> assubscreenscripts;
249
250 vector<string> ZQincludePaths;
251
252 int32_t CSET_SIZE = 16;
253 int32_t CSET_SHFT = 4;
254 //editbox_data temp_eb_data;
255 /*
256 #define CSET(x) ((x)<<CSET_SHFT)
257 #define csBOSS 14
258 */
259
260 /*
261 enum { m_block, m_coords, m_flags, m_guy, m_warp, m_misc, m_layers,
262 m_menucount };
263 */
264 void update_combo_cycling();
265 void update_freeform_combos();
266
267 /*
268 #define MAXMICE 14
269 #define MAXARROWS 8
270 #define SHADOW_DEPTH 2
271 */
272 int32_t coord_timer=0, coord_frame=0;
273 int32_t blackout_color, zq_screen_w, zq_screen_h;
274 int32_t draw_mode=0;
275
276 12 size_and_pos minimap;
277 12 size_and_pos real_minimap;
278
279 12 size_and_pos minimap_zoomed;
280 12 size_and_pos real_minimap_zoomed;
281
282 12 size_and_pos map_page_bar[9];
283 int32_t mappage_count = 9;
284
285 12 size_and_pos combolist[MAX_COMBO_COLS];
286 12 size_and_pos combolistscrollers[MAX_COMBO_COLS];
287 int32_t num_combo_cols = MAX_COMBO_COLS;
288
289 static bool zoom_in_btn_disabled;
290 static bool zoom_out_btn_disabled;
291 12 size_and_pos zoominbtn;
292 12 size_and_pos zoomoutbtn;
293 12 size_and_pos compactbtn;
294 12 size_and_pos mainbar;
295
296 12 size_and_pos screrrorpos;
297
298 12 size_and_pos comboaliaslist[MAX_COMBO_COLS];
299 12 size_and_pos comboalias_preview;
300 12 size_and_pos combopool_preview;
301 12 size_and_pos combopool_prevbtn;
302
303 12 size_and_pos combo_merge_btn;
304
305 12 size_and_pos combo_preview;
306 12 size_and_pos combo_preview2;
307 12 size_and_pos combo_preview_text1;
308 12 size_and_pos combo_preview_text2;
309 12 size_and_pos combolist_window;
310 12 size_and_pos drawmode_btn;
311 12 size_and_pos main_panel;
312 12 size_and_pos squares_panel;
313 12 size_and_pos preview_panel;
314 12 size_and_pos layer_panel;
315 12 size_and_pos preview_text;
316
317 12 size_and_pos favorites_window;
318 12 size_and_pos favorites_list;
319 12 size_and_pos favorites_x;
320 12 size_and_pos favorites_infobtn;
321 12 size_and_pos favorites_zoombtn;
322 12 size_and_pos favorites_pgleft;
323 12 size_and_pos favorites_pgright;
324
325 12 size_and_pos commands_window;
326 12 size_and_pos commands_list;
327 12 size_and_pos commands_x;
328 12 size_and_pos commands_infobtn;
329 12 size_and_pos commands_zoombtn;
330 12 size_and_pos commands_txt;
331
332 12 size_and_pos squarepanel_swap_btn;
333 12 size_and_pos squarepanel_up_btn;
334 12 size_and_pos squarepanel_down_btn;
335 12 size_and_pos itemsqr_pos;
336 12 size_and_pos flagsqr_pos;
337 12 size_and_pos stairsqr_pos;
338 12 size_and_pos warparrival_pos;
339 12 size_and_pos warpret_pos[4];
340 12 size_and_pos enemy_prev_pos;
341
342 12 size_and_pos txtoffs_single;
343 12 size_and_pos txtoffs_double_1;
344 12 size_and_pos txtoffs_double_2;
345 int32_t panel_align = 1;
346
347 int32_t command_buttonwidth = 88;
348 int32_t command_buttonheight = 19;
349
350 int32_t layerpanel_buttonwidth = 58;
351 int32_t layerpanel_buttonheight = 16;
352
353 int32_t layerpanel_checkbox_hei = 13;
354 int32_t layerpanel_checkbox_wid = 13;
355
356 int32_t favorite_combos[MAXFAVORITECOMBOS];
357 byte favorite_combo_modes[MAXFAVORITECOMBOS];
358 bool ShowFavoriteComboModes;
359 byte FavoriteComboPage;
360
361 char comboprev_buf[512] = {0};
362 char comboprev_buf2[512] = {0};
363 FONT* txfont;
364
365 const char *roomtype_string[MAXROOMTYPES] =
366 {
367 "(None)","Special Item","Pay for Info","Secret Money","Gamble",
368 "Door Repair","Red Potion or Heart Container","Feed the Goriya","Triforce Check",
369 "Potion Shop","Shop","More Bombs","Leave Money or Life","10 Rupees",
370 "3-Stair Warp","Ganon","Zelda", "-<item pond>", "1/2 Magic Upgrade", "Learn Slash", "More Arrows","Take One Item"
371 };
372
373 const char *catchall_string[MAXROOMTYPES] =
374 {
375 "Generic Catchall","Special Item","Info Type","Amount","Generic Catchall","Repair Fee","Generic Catchall","Generic Catchall","Generic Catchall","Shop Type",
376 "Shop Type","Price","Price","Generic Catchall","Warp Ring","Generic Catchall","Generic Catchall", "Generic Catchall", "Generic Catchall",
377 "Generic Catchall", "Price","Shop Type","Bottle Shop Type"
378 };
379
380 #define MAXPOOLCOMBOS MAXFAVORITECOMBOS
381
382 struct cmbdat_pair
383 {
384 int32_t data;
385 byte cset;
386 15120 cmbdat_pair() { clear(); }
387 25200 void clear()
388 {
389 25200 data = -1;
390 25200 cset = 0;
391 25200 }
392 bool valid() const
393 {
394 return data > -1;
395 }
396 };
397 bool pool_dirty=true;
398 12 cmbdat_pair pool_combos[MAXPOOLCOMBOS];
399 static std::vector<byte> pool;
400
401 bool pool_valid()
402 {
403 if(pool_dirty)
404 {
405 pool.clear();
406 for(auto q = 0; q < MAXPOOLCOMBOS; ++q)
407 {
408 if(pool_combos[q].valid())
409 pool.push_back(q);
410 }
411 pool_dirty = false;
412 }
413 return pool.size() > 0;
414 }
415 cmbdat_pair const& get_pool_combo()
416 {
417 if(!pool_valid()) return pool_combos[0];
418 auto ind = zc_rand(pool.size()-1);
419 return pool_combos[pool.at(ind)];
420 }
421
422 int32_t mouse_scroll_h;
423
424 // 'mapscreen' refers to the area of the editor where the screen is drawn.
425 int32_t mapscreen_x, mapscreen_y, showedges, showallpanels;
426 // The scale of the entire mapscreen area. This varies based on compact/extended mode.
427 static int mapscreen_screenunit_scale;
428 // The scale of an individual screen being drawn. This is `mapscreen_screenunit_scale / Map.getViewSize()`.
429 static double mapscreen_single_scale;
430 // 4 is roughly the largest value where things render okay. Beyond that, our low bitmap resolution results in tons
431 // of downsampling. Let users go to 16 anyway.
432 static int mapscreen_num_screens_to_draw_max = 16;
433 // The valid layers for the current screen(s).
434 static bool mapscreen_valid_layers[6];
435
436 struct VisibleScreen
437 {
438 int dx, dy;
439 int xoff, yoff;
440 mapscr* scr;
441 int screen;
442 };
443 static std::vector<VisibleScreen> visible_screens;
444 static VisibleScreen* active_visible_screen = nullptr;
445
446 static void set_active_visible_screen(mapscr* scr)
447 {
448 active_visible_screen = nullptr;
449 for (auto& visible_screen : visible_screens)
450 {
451 if (visible_screen.scr == scr)
452 {
453 active_visible_screen = &visible_screen;
454 break;
455 }
456 }
457 }
458
459 static ComboPosition get_mapscreen_mouse_combo_pos()
460 {
461 int startxint = mapscreen_x+(showedges?int(16*mapscreen_single_scale):0);
462 int startyint = mapscreen_y+(showedges?int(16*mapscreen_single_scale):0);
463 int cx = (gui_mouse_x()-startxint)/(16*mapscreen_single_scale);
464 int cy = (gui_mouse_y()-startyint)/(16*mapscreen_single_scale);
465 return ComboPosition{cx, cy};
466 }
467
468 static void refresh_visible_screens()
469 {
470 int num_screens = Map.getViewSize();
471 int screen_width = mapscreenbmp->w * mapscreen_single_scale;
472 int screen_height = mapscreenbmp->h * mapscreen_single_scale;
473
474 visible_screens.clear();
475 for (int dx = 0; dx < num_screens; dx++)
476 {
477 for (int dy = 0; dy < num_screens; dy++)
478 {
479 int mx = Map.getViewScr()%16 + dx;
480 int my = Map.getViewScr()/16 + dy;
481 if (mx < 0 || mx >= 16 || my < 0 || my >= 9)
482 continue;
483
484 int screen = Map.getViewScr() + dx + dy * 16;
485 if (screen >= MAPSCRS)
486 continue;
487
488 mapscr* scr = Map.Scr(screen);
489 int offx = dx * screen_width;
490 int offy = dy * screen_height;
491 visible_screens.emplace_back(VisibleScreen{dx, dy, offx, offy, scr, screen});
492 }
493 }
494
495 for (int i = 0; i < 6; i++)
496 {
497 mapscreen_valid_layers[i] = false;
498 for (auto& vis_screen : visible_screens)
499 {
500 mapscreen_valid_layers[i] |= vis_screen.scr->layermap[i] > 0;
501 }
502 }
503 }
504
505 int32_t readsize, writesize;
506 bool fake_pack_writing=false;
507
508 int32_t showxypos_x;
509 int32_t showxypos_y;
510 int32_t showxypos_w;
511 int32_t showxypos_h;
512 int32_t showxypos_color;
513 int32_t showxypos_ffc=-1000;
514 bool showxypos_icon=false;
515
516 int32_t showxypos_cursor_x;
517 int32_t showxypos_cursor_y;
518 bool showxypos_cursor_icon=false;
519 int32_t showxypos_cursor_color;
520 bool showxypos_dummy = false;
521
522 bool canfill=true; //to prevent double-filling (which stops undos)
523 int32_t lens_hint_item[MAXITEMS][2]; //aclk, aframe
524 int32_t lens_hint_weapon[MAXWPNS][5]; //aclk, aframe, dir, x, y
525 //int32_t mode, switch_mode, orig_mode;
526 int32_t tempmode=GFX_AUTODETECT;
527 RGB_MAP zq_rgb_table;
528 COLOR_MAP trans_table, trans_table2;
529 MIDI *song=NULL;
530 BITMAP *menu1, *menu3, *mapscreenbmp, *tmp_scr, *screen2, *mouse_bmp[MOUSE_BMP_MAX][4], *mouse_bmp_1x[MOUSE_BMP_MAX][4], *icon_bmp[ICON_BMP_MAX][4], *flag_bmp[16][4], *select_bmp[2], *dmapbmp_small, *dmapbmp_large;
531 BITMAP *arrow_bmp[MAXARROWS],*brushbmp, *brushscreen; //*brushshadowbmp;
532 byte *colordata=NULL, *trashbuf=NULL;
533 itemdata *itemsbuf;
534 wpndata *wpnsbuf;
535 comboclass *combo_class_buf;
536 guydata *guysbuf;
537 item_drop_object item_drop_sets[MAXITEMDROPSETS];
538 12 newcombo curr_combo;
539 PALETTE RAMpal;
540 midi_info Midi_Info;
541 bool zq_showpal=false;
542 bool is_compact = false;
543
544 int pixeldb = 1;
545 int infobg = 1;
546 bool large_merged_combopane = false;
547 bool compact_merged_combopane = true;
548 bool large_zoomed_fav = false;
549 bool compact_zoomed_fav = true;
550 bool large_zoomed_cmd = false;
551 bool compact_zoomed_cmd = true;
552
553 bool compact_square_panels = false;
554 int compact_active_panel = 0;
555
556 int combo_col_scale = 1;
557
558 std::vector<std::shared_ptr<zasm_script>> zasm_scripts;
559 script_data *ffscripts[NUMSCRIPTFFC];
560 script_data *itemscripts[NUMSCRIPTITEM];
561 script_data *guyscripts[NUMSCRIPTGUYS];
562 script_data *lwpnscripts[NUMSCRIPTWEAPONS];
563 script_data *ewpnscripts[NUMSCRIPTWEAPONS];
564 script_data *globalscripts[NUMSCRIPTGLOBAL];
565 script_data *genericscripts[NUMSCRIPTSGENERIC];
566 script_data *playerscripts[NUMSCRIPTHERO];
567 script_data *screenscripts[NUMSCRIPTSCREEN];
568 script_data *dmapscripts[NUMSCRIPTSDMAP];
569 script_data *itemspritescripts[NUMSCRIPTSITEMSPRITE];
570 script_data *comboscripts[NUMSCRIPTSCOMBODATA];
571 script_data *subscreenscripts[NUMSCRIPTSSUBSCREEN];
572
573 extern string zScript;
574 char zScriptBytes[512];
575 char zLastVer[512] = { 0 };
576 SAMPLE customsfxdata[WAV_COUNT];
577 uint8_t customsfxflag[WAV_COUNT>>3];
578 int32_t sfxdat=1;
579
580 int32_t onImport_ComboAlias();
581 int32_t onExport_ComboAlias();
582
583 void set_console_state();
584
585 void clearConsole()
586 {
587 if(!console_is_open) return;
588 zscript_coloured_console.cls(CConsoleLoggerEx::COLOR_BACKGROUND_BLACK);
589 zscript_coloured_console.gotoxy(0,0);
590 zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_BLUE | CConsoleLoggerEx::COLOR_INTENSITY |
591 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"ZQuest Classic Logging Console\n");
592 }
593
594 void initConsole()
595 {
596 if(console_is_open) return;
597 console_is_open = 1;
598 set_console_state();
599 zscript_coloured_console.Create("ZQuest Classic Logging Console", 600, 200);
600 clearConsole();
601 }
602
603 11 void killConsole()
604 {
605
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(!console_is_open) return;
606 console_is_open = 0;
607 set_console_state();
608 zscript_coloured_console.kill();
609 11 }
610
611 int toggleConsole()
612 {
613 console_is_open ? killConsole() : initConsole();
614 zc_set_config("zquest","open_debug_console",console_is_open?1:0);
615 return D_O_K;
616 }
617
618 int showHotkeys()
619 {
620 hotkeys_toggle_display(!hotkeys_is_active());
621 return D_O_K;
622 }
623
624 typedef int32_t (*intF)();
625 typedef struct command_pair
626 {
627 char name[80];
628 int32_t flags;
629 intF command;
630 } command_pair;
631
632 extern map_and_screen map_page[MAX_MAPPAGE_BTNS];
633
634 int32_t do_OpenQuest()
635 {
636 return onOpen();
637 }
638
639 int32_t do_NewQuest()
640 {
641 //clear the panel recent screen buttons to prevent crashes from invalid maps
642 for ( int32_t q = 0; q < 9; q++ )
643 {
644 map_page[q].map = 0;
645 map_page[q].screen = 0;
646 }
647 Map.setCurrMap(0);
648 Map.setCurrScr(0);
649 return onNew();
650 }
651
652 extern int CheckerCol1, CheckerCol2;
653 int32_t alignment_arrow_timer=0;
654 int32_t Flip=0,Combo=0,CSet=2,current_combolist=0,current_comboalist=0,current_cpoollist=0,current_cautolist=0,current_mappage=0;
655 int32_t Flags=0,Flag=0,menutype=(m_block);
656 int MouseScroll = 0, SavePaths = 0, CycleOn = 0, ShowGrid = 0, ShowScreenGrid = 0, ShowRegionGrid = 0, GridColor = 15, ShowCurScreenOutline = 1,
657 CmbCursorCol = 15, TilePgCursorCol = 15, CmbPgCursorCol = 15, TTipHLCol = 13,
658 TileProtection = 0, ComboProtection = 0, NoScreenPreview = 0, MMapCursorStyle = 0,
659 LayerDitherBG = -1, LayerDitherSz = 2, RulesetDialog = 0,
660 EnableTooltips = 0, TooltipsHighlight = 0, ShowFFScripts = 0, ShowSquares = 0,
661 ShowFFCs = 0, ShowInfo = 0, skipLayerWarning = 0,
662 DisableLPalShortcuts = 1, DisableCompileConsole = 0, numericalFlags = 0,
663 ActiveLayerHighlight = 0, DragCenterOfSquares = 0;
664 uint8_t InvalidBG = 0;
665 bool NoHighlightLayer0 = false;
666 int32_t FlashWarpSquare = -1, FlashWarpClk = 0; // flash the destination warp return when ShowSquares is active
667 uint8_t ViewLayer3BG = 0, ViewLayer2BG = 0;
668 int32_t window_width, window_height;
669 bool ShowFPS = false, SaveDragResize = false, DragAspect = false, SaveWinPos=false;
670 bool allowHideMouse = false;
671 double aspect_ratio = LARGE_H / double(LARGE_W);
672 int window_min_width = 0, window_min_height = 0;
673 int32_t ComboBrush = 0; //show the brush instead of the normal mouse
674 int32_t ComboBrushPause = 0; //temporarily disable the combo brush
675 int32_t FloatBrush = 0; //makes the combo brush float a few pixels up and left
676 int AutoBrush = 0; //Drag to size the brush on the combo panes
677 bool AutoBrushRevert = false; //Revert after placing
678 int LinkedScroll = 0;
679 //complete with shadow
680 int32_t OpenLastQuest = 0; //makes the program reopen the quest that was
681 //open at the time you quit
682 int32_t ShowMisalignments = 0; //makes the program display arrows over combos that are
683 //not aligned with the next screen.
684 int32_t AnimationOn = 0; //animate the combos in zquest?
685 int32_t AutoBackupRetention = 0; //use auto-backup feature? if so, how many backups (1-10) to keep
686 int32_t AutoSaveInterval = 0; //how often a timed autosave is made (not overwriting the current file)
687 int32_t UncompressedAutoSaves = 0; //should timed saves be uncompressed/encrypted?
688 int32_t KeyboardRepeatDelay = 0; //the time in milliseconds after holding down a key that the key starts to repeat
689 int32_t KeyboardRepeatRate = 0; //the time in milliseconds between each repetition of a repeated key
690
691 time_t auto_save_time_start, auto_save_time_current;
692 double auto_save_time_diff = 0;
693 int32_t AutoSaveRetention = 0; //how many autosaves of a quest to keep
694 int32_t ImportMapBias = 0; //tells what has precedence on map importing
695 int32_t BrushWidth=1, BrushHeight=1;
696 bool saved=true;
697 bool __debug=false;
698 int32_t LayerMaskInt[7]={0};
699 int32_t CurrentLayer=0;
700 int32_t DuplicateAction[4]={0};
701 int32_t OnlyCheckNewTilesForDuplicates = 0;
702 int32_t try_recovering_missing_scripts = 0;
703
704 uint8_t PreFillTileEditorPage = 0, PreFillComboEditorPage = 0;
705 int32_t DMapEditorLastMaptileUsed = 0;
706
707 /*
708 , HorizontalDuplicateAction;
709 int32_t VerticalDuplicateAction, BothDuplicateAction;
710 */
711 word msg_count = 0;
712 int32_t LeechUpdate = 0;
713 int32_t LeechUpdateTiles = 0;
714 int32_t SnapshotFormat = 0;
715 byte SnapshotScale = 0;
716
717 byte Color = 0;
718 extern int32_t jwin_pal[jcMAX];
719 int32_t gui_colorset=99;
720
721 static int32_t combo_apos=0; //currently selected combo alias
722 int32_t alias_origin=0;
723 int32_t alias_cset_mod=0;
724
725 static int32_t combo_pool_pos=0; //currently selected combo pool
726 bool weighted_cpool = true;
727 bool cpool_prev_visible = false;
728
729 static int32_t combo_auto_pos=0; //currently selected autocombo
730 byte cauto_height = 1;
731
732 bool trip=false;
733
734 int32_t fill_type=1;
735
736 bool first_save=false;
737 char *filepath,*midipath,*datapath,*imagepath,*tmusicpath,*last_timed_save;
738 string helpstr, zstringshelpstr;
739
740 ZCMUSIC *zcmusic = NULL;
741 ZCMIXER *zcmixer = NULL;
742 int32_t midi_volume = 255;
743 extern int32_t prv_mode;
744 int32_t prv_warp = 0;
745 int32_t prv_twon = 0;
746 int32_t ff_combo = 0;
747
748 int32_t Frameskip = 0, RequestedFPS = 60, zqUseWin32Proc = 1;
749 int32_t zqColorDepth = 8;
750 int32_t joystick_index=0;
751
752 11 void set_last_timed_save(char const* buf)
753 {
754
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
11 if(buf && buf[0])
755 {
756 if(buf != last_timed_save)
757 strcpy(last_timed_save, buf);
758 }
759 else
760 {
761 11 last_timed_save[0] = 0;
762 11 buf = nullptr;
763 }
764 11 zc_set_config("zquest","last_timed_save",buf);
765 11 }
766
767 void loadlvlpal(int32_t level);
768 bool get_debug()
769 {
770 return __debug;
771 //return true;
772 }
773
774 void set_debug(bool d)
775 {
776 __debug=d;
777 return;
778 }
779
780 bool handle_quit()
781 {
782 if(onExit()==D_CLOSE)
783 return (exiting_program = true);
784 return false;
785 }
786 bool handle_close_btn_quit()
787 {
788 if(close_button_quit)
789 {
790 close_button_quit=false;
791 return handle_quit();
792 }
793 return false;
794 }
795 // **** Timers ****
796
797 volatile int32_t lastfps=0;
798 volatile int32_t framecnt=0;
799 size_t cpoolbrush_index = 0;
800
801 // quest data
802 12 zquestheader header;
803 byte midi_flags[MIDIFLAGS_SIZE];
804 byte music_flags[MUSICFLAGS_SIZE];
805 byte *quest_file;
806 int32_t msg_strings_size;
807 zctune *customtunes;
808 //emusic *enhancedMusic;
809 ZCHEATS zcheats;
810 byte use_cheats;
811 byte use_tiles;
812 // Note: may not be null-terminated (must refactor writecolordata to fix).
813 char palnames[MAXLEVELS][17];
814 char zquestdat_sig[52];
815 char qstdat_str[2048];
816
817 int32_t gme_track=0;
818
819 int32_t dlevel; // just here until gamedata is properly done
820
821 12 bool bad_version(int32_t ver)
822 {
823
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(ver < 0x170)
824 return true;
825
826 12 return false;
827 12 }
828
829 // These are for drawing eyeballs correctly in combo_tile.
830 zfix HeroModifiedX()
831 {
832 return gui_mouse_x() - 7;
833 }
834 zfix HeroModifiedY()
835 {
836 return gui_mouse_y() - 7;
837 }
838
839
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu import_250_menu
840 48 {
841
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&DMaps", onImport_DMaps },
842
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combo Table", onImport_Combos },
843
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combo Alias", onImport_ComboAlias },
844 };
845
846
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu import_graphics
847 180 {
848
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Palettes", onImport_Pals },
849
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
850
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Tileset (&Full)", onImport_Tiles },
851
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Tile Pack", onImport_Tilepack },
852
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "T&ile Pack to...", onImport_Tilepack_To },
853
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
854
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combo Set (Range)", onImport_Combos },
855
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Combo Pack (Full, 1:1)", onImport_Combopack },
856
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Combo Pack to... (Dest)", onImport_Combopack_To },
857
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
858
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Combo &Alias Pack", onImport_Comboaliaspack },
859
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Combo A&lias Pack to...", onImport_Comboaliaspack_To },
860
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
861
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Doorsets", onImport_Doorset },
862 };
863
864
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu import_menu
865 120 {
866
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Enemies", onImport_Guys },
867
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Map", onImport_Map },
868
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&DMaps", onImport_DMaps },
869
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Strings (.tsv)", onImport_StringsTSV },
870
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "String Table (deprecated)", onImport_Msgs },
871
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
872
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Graphics", &import_graphics },
873
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
874
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "2.50 (Broken)", &import_250_menu },
875 };
876
877
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu export_250_menu
878 60 {
879
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&DMaps", onExport_DMaps },
880
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combo Table", onExport_Combos },
881
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combo Alias", onExport_ComboAlias },
882
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Graphics Pack", onExport_ZGP },
883 };
884
885
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu zq_help_menu
886 36 {
887
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Editor Help", onHelp },
888
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Strings Help", onZstringshelp },
889 };
890
891
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu export_graphics
892 144 {
893
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Palettes", onExport_Pals },
894
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
895
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Tileset (&Full)", onExport_Tiles },
896
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Tile Pack", onExport_Tilepack },
897
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
898
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combo Set", onExport_Combos },
899
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Combo Pack", onExport_Combopack },
900
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
901
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Combo &Alias Pack", onExport_Comboaliaspack },
902
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
903
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Doorsets", onExport_Doorset },
904 };
905
906
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu export_menu
907 132 {
908 #ifdef _WIN32
909 { "&Package", onExport_Package },
910 #endif
911
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Enemies", onExport_Guys },
912
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Map", onExport_Map },
913
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&DMaps", onExport_DMaps },
914
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
915
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Strings (.tsv)", onExport_StringsTSV },
916
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "String Table (deprecated)", onExport_Msgs },
917
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
918
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Graphics", &export_graphics },
919
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
920
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "2.50 (Broken)", &export_250_menu },
921 };
922
923
924
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu recent_menu
925 132 {
926
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
927
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
928
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
929
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
930
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
931
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
932
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
933
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
934
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
935
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
936 };
937 static char rec_menu_fullpaths[10][512];
938 static char rec_menu_strs[10][64];
939
940 int32_t customOpen(char const* path);
941 void do_recent_quest(uint32_t ind)
942 {
943 if(ind > 9) return;
944 strcpy(temppath, rec_menu_fullpaths[ind]);
945 customOpen(temppath);
946 }
947 int32_t do_RecentQuest_0() { do_recent_quest(0); return D_O_K; }
948 int32_t do_RecentQuest_1() { do_recent_quest(1); return D_O_K; }
949 int32_t do_RecentQuest_2() { do_recent_quest(2); return D_O_K; }
950 int32_t do_RecentQuest_3() { do_recent_quest(3); return D_O_K; }
951 int32_t do_RecentQuest_4() { do_recent_quest(4); return D_O_K; }
952 int32_t do_RecentQuest_5() { do_recent_quest(5); return D_O_K; }
953 int32_t do_RecentQuest_6() { do_recent_quest(6); return D_O_K; }
954 int32_t do_RecentQuest_7() { do_recent_quest(7); return D_O_K; }
955 int32_t do_RecentQuest_8() { do_recent_quest(8); return D_O_K; }
956 int32_t do_RecentQuest_9() { do_recent_quest(9); return D_O_K; }
957
958 2 void refresh_recent_menu()
959 {
960 2 int32_t (*procs[10])(void) = {
961 do_RecentQuest_0, do_RecentQuest_1, do_RecentQuest_2, do_RecentQuest_3,
962 do_RecentQuest_4, do_RecentQuest_5, do_RecentQuest_6,
963 do_RecentQuest_7, do_RecentQuest_8, do_RecentQuest_9
964 };
965
5/8
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
2 static MenuItem nilitem("---",nullptr,nullopt,true);
966
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 20 times.
22 for(auto q = 0; q < 10; ++q)
967 {
968 20 MenuItem& mit = *recent_menu.at(q);
969 20 bool valid = rec_menu_fullpaths[q][0] != '-';
970
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if(valid)
971 mit = MenuItem(rec_menu_strs[q],procs[q]);
972 20 else mit = nilitem;
973 20 }
974 2 }
975
976 1 void load_recent_quests()
977 {
978 1 char configname[64] = "rec_qst_";
979 1 char* ptr = &configname[strlen(configname)];
980 1 char buf[512] = {0};
981
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1 times.
11 for(auto q = 0; q < 10; ++q)
982 {
983 10 sprintf(ptr, "%d", q); //increment the configname value
984 10 char const* qst_str = zc_get_config("recent",configname,nullptr);
985
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if(qst_str[0])
986 {
987 strncpy(rec_menu_fullpaths[q], qst_str, 511);
988 relativize_path(buf, rec_menu_fullpaths[q]);
989 if(strlen(buf) > 62)
990 {
991 buf[60] = buf[61] = buf[62] = '.'; //add "..." as the last 3 characters
992 }
993 strncpy(rec_menu_strs[q], buf, 63);
994 }
995 else
996 {
997 10 strcpy(rec_menu_fullpaths[q], "---");
998 10 strcpy(rec_menu_strs[q], "---");
999 }
1000 10 rec_menu_fullpaths[q][511] = 0;
1001 10 rec_menu_strs[q][63] = 0;
1002 10 }
1003 1 refresh_recent_menu();
1004 1 }
1005
1006 void write_recent_quests()
1007 {
1008 char configname[64] = "rec_qst_";
1009 char* ptr = &configname[strlen(configname)];
1010 for(auto q = 0; q < 10; ++q)
1011 {
1012 sprintf(ptr, "%d", q); //increment the configname value
1013 zc_set_config("recent",configname,(rec_menu_fullpaths[q][0]!='-') ? rec_menu_fullpaths[q] : nullptr);
1014 }
1015 }
1016
1017 void update_recent_quest(char const* path)
1018 {
1019 int32_t ind = -1;
1020 for(auto q = 0; q < 10; ++q)
1021 {
1022 if(!strcmp(path, rec_menu_fullpaths[q]))
1023 {
1024 ind = q;
1025 break;
1026 }
1027 }
1028 if(ind > -1)
1029 {
1030 for(auto q = ind; q > 0; --q)
1031 {
1032 strcpy(rec_menu_fullpaths[q], rec_menu_fullpaths[q-1]);
1033 strcpy(rec_menu_strs[q], rec_menu_strs[q-1]);
1034 }
1035 }
1036 else
1037 {
1038 int32_t free_ind = 9; //if none found, override the last index
1039 for(auto q = 0; q < 9; ++q)
1040 {
1041 if(rec_menu_fullpaths[q][0] == '-')
1042 {
1043 free_ind = q;
1044 break;
1045 }
1046 }
1047
1048 for(auto q = free_ind; q > 0; --q)
1049 {
1050 strcpy(rec_menu_fullpaths[q], rec_menu_fullpaths[q-1]);
1051 strcpy(rec_menu_strs[q], rec_menu_strs[q-1]);
1052 }
1053 }
1054 char buf[512] = {0};
1055 strcpy(rec_menu_fullpaths[0], path);
1056 relativize_path(buf, rec_menu_fullpaths[0]);
1057 if(strlen(buf) > 62)
1058 {
1059 buf[60] = buf[61] = buf[62] = '.'; //add "..." as the last 3 characters
1060 }
1061 strncpy(rec_menu_strs[0], buf, 63);
1062 refresh_recent_menu();
1063 zc_set_config("zquest",last_quest_name,path);
1064 write_recent_quests();
1065 }
1066
1067 void reload_zq_gui()
1068 {
1069 init_custom_fonts();
1070 load_size_poses();
1071 refresh_visible_screens();
1072 update_combobrush();
1073 refresh(rCLEAR|rALL);
1074 }
1075 void change_mapscr_zoom(int delta)
1076 {
1077 int num_screens = Map.getViewSize();
1078 num_screens = std::clamp(num_screens + delta, 1, mapscreen_num_screens_to_draw_max);
1079 Map.setViewSize(num_screens);
1080 std::string qst_cfg_header = qst_cfg_header_from_path(filepath);
1081 zc_set_config(qst_cfg_header.c_str(), "zoom_num_screens", Map.getViewSize());
1082 reload_zq_gui();
1083 }
1084 void toggle_is_compact()
1085 {
1086 is_compact = !is_compact;
1087 zc_set_config("ZQ_GUI","compact_mode",is_compact?1:0);
1088 reload_zq_gui();
1089 }
1090 void toggle_merged_mode()
1091 {
1092 if(is_compact)
1093 {
1094 compact_merged_combopane = !compact_merged_combopane;
1095 zc_set_config("ZQ_GUI","merge_cpane_compact",compact_merged_combopane?1:0);
1096 }
1097 else
1098 {
1099 large_merged_combopane = !large_merged_combopane;
1100 zc_set_config("ZQ_GUI","merge_cpane_large",large_merged_combopane?1:0);
1101 }
1102 reload_zq_gui();
1103 }
1104 void toggle_compact_sqr_mode()
1105 {
1106 compact_square_panels = !compact_square_panels;
1107 zc_set_config("ZQ_GUI","square_panels_compact",compact_square_panels?1:0);
1108 reload_zq_gui();
1109 }
1110 void cycle_compact_sqr(bool down)
1111 {
1112 if(!(is_compact && compact_square_panels))
1113 return;
1114 static const int num_panels = 3;
1115 if(down)
1116 compact_active_panel = (compact_active_panel+1)%num_panels;
1117 else
1118 compact_active_panel = (compact_active_panel-1+num_panels)%num_panels;
1119 reload_zq_gui();
1120 }
1121 void toggle_favzoom_mode()
1122 {
1123 if(is_compact)
1124 {
1125 compact_zoomed_fav = !compact_zoomed_fav;
1126 zc_set_config("ZQ_GUI","zoom_fav_compact",compact_zoomed_fav?1:0);
1127 }
1128 else
1129 {
1130 large_zoomed_fav = !large_zoomed_fav;
1131 zc_set_config("ZQ_GUI","zoom_fav_large",large_zoomed_fav?1:0);
1132 }
1133 reload_zq_gui();
1134 }
1135 void toggle_cmdzoom_mode()
1136 {
1137 if(is_compact)
1138 {
1139 compact_zoomed_cmd = !compact_zoomed_cmd;
1140 zc_set_config("ZQ_GUI","zoom_cmd_compact",compact_zoomed_cmd?1:0);
1141 }
1142 else
1143 {
1144 large_zoomed_cmd = !large_zoomed_cmd;
1145 zc_set_config("ZQ_GUI","zoom_cmd_large",large_zoomed_cmd?1:0);
1146 }
1147 reload_zq_gui();
1148 }
1149
1150 enum
1151 {
1152 MENUID_FILE_SAVE,
1153 MENUID_FILE_SAVEAS,
1154 MENUID_FILE_REVERT,
1155 };
1156
1157
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu file_menu
1158 156 {
1159
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&New", do_NewQuest },
1160
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Open", do_OpenQuest },
1161
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Recent", &recent_menu },
1162
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1163
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Save", onSave, MENUID_FILE_SAVE },
1164
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Save &as...", onSaveAs, MENUID_FILE_SAVEAS },
1165
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Revert", onRevert, MENUID_FILE_REVERT },
1166
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1167
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Import", &import_menu },
1168
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Export", &export_menu },
1169 #ifndef __EMSCRIPTEN__
1170
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1171
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "E&xit", handle_quit },
1172 #endif
1173 };
1174
1175 enum
1176 {
1177 MENUID_MAPS_NEXT,
1178 MENUID_MAPS_PREV,
1179 };
1180
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu maps_menu
1181 72 {
1182
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Goto Map...", onGotoMap },
1183
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Next Map", onIncMap, MENUID_MAPS_NEXT },
1184
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Previous Map", onDecMap, MENUID_MAPS_PREV },
1185
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1186
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "D&elete Map", onDeleteMap },
1187 };
1188
1189
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu misc_menu
1190 120 {
1191
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "S&ubscreens", onEditSubscreens },
1192
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Shop Types", onShopTypes },
1193
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Bottle Types", onBottleTypes },
1194
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Bottle S&hop Types", onBottleShopTypes },
1195
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Info Types", onInfoTypes },
1196
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Warp Rings", onWarpRings },
1197
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Triforce Pieces", onTriPieces },
1198
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&End String", onEndString },
1199
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Item &Drop Sets", onItemDropSets },
1200 };
1201
1202
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu spr_menu
1203 48 {
1204
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Sprite Data", onCustomWpns },
1205
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Hero", onCustomHero },
1206
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Misc Sprites", onMiscSprites },
1207 };
1208
1209
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 NewMenu colors_menu
1210 48 {
1211
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Main ", onColors_Main },
1212
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Levels ", onColors_Levels },
1213
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Sprites ", onColors_Sprites },
1214 };
1215
1216
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu defs_menu
1217 108 {
1218
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Palettes", onDefault_Pals },
1219
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Tiles", onDefault_Tiles },
1220
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combos", onDefault_Combos },
1221
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Items", onDefault_Items },
1222
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Enemies", onDefault_Guys },
1223
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Sprite Data", onDefault_Weapons },
1224
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Map Styles", onDefault_MapStyles },
1225
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "SF&X Data", onDefault_SFX },
1226 };
1227
1228 int32_t onEditComboAlias();
1229 int32_t onEditComboPool();
1230 int32_t onEditAutoCombo();
1231
1232
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu graphics_menu
1233 120 {
1234
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Palettes ", &colors_menu },
1235
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Sprites ", &spr_menu },
1236
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combos", onCombos },
1237
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Tiles", onTiles },
1238
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Game icons", onIcons },
1239
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Misc co&lors", onMiscColors },
1240
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Map styles", onMapStyles },
1241
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Door Combo Sets", onDoorCombos },
1242
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Combo &Aliases", onEditComboAlias },
1243 };
1244
1245
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu audio_menu
1246 48 {
1247
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "SF&X Data", onSelectSFX },
1248
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&MIDIs", onMidis },
1249
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Mis&c SFX", onMiscSFX },
1250 };
1251
1252 void set_rules(byte* newrules);
1253
1254 void call_testqst_dialog();
1255 int32_t onTestQst()
1256 {
1257 call_testqst_dialog();
1258 return D_O_K;
1259 }
1260
1261 int32_t onRulesDlg()
1262 {
1263 call_qr_dialog(21, set_rules);
1264 return D_O_K;
1265 }
1266
1267 int32_t onRulesSearch()
1268 {
1269 call_qrsearch_dialog(set_rules);
1270 return D_O_K;
1271 }
1272
1273 int32_t onZScriptSettings()
1274 {
1275 ScriptRulesDialog(quest_rules, 17, [](byte* newrules)
1276 {
1277 saved = false;
1278 memcpy(quest_rules, newrules, QR_SZ);
1279 unpack_qrs();
1280 }).show();
1281 return D_O_K;
1282 }
1283
1284 void call_zinf_dlg();
1285 int32_t onZInfo()
1286 {
1287 call_zinf_dlg();
1288 return D_O_K;
1289 }
1290
1291
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu quest_menu
1292 204 {
1293
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Options ", onRulesDlg },
1294
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Test", onTestQst },
1295
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Items", onCustomItems },
1296
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Enemies", onCustomEnemies },
1297
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Hero", onCustomHero },
1298
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Strings", onStrings },
1299
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&DMaps", onDmaps },
1300
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Map Settings", onMaps },
1301
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "I&nit Data", onInit },
1302
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Misc D&ata ", &misc_menu },
1303
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&ZInfo", onZInfo },
1304
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1305
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Graphics ", &graphics_menu },
1306
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "A&udio ", &audio_menu },
1307
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1308
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "De&faults ", &defs_menu },
1309 };
1310
1311
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu paste_menu
1312 36 {
1313
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Paste &To All", onPasteToAll },
1314
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Paste &All To All", onPasteAllToAll },
1315 };
1316
1317
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu paste_item_menu
1318 156 {
1319
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Undercombo", onPasteUnderCombo },
1320
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Secret Combos", onPasteSecretCombos },
1321
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Freeform Combos", onPasteFFCombos },
1322
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Screen &Data", onPasteScreenData },
1323
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Warps", onPasteWarps },
1324
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Warp &Return", onPasteWarpLocations },
1325
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Enemies", onPasteEnemies },
1326
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Room &Type Data", onPasteRoom },
1327
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Guy/String", onPasteGuy },
1328
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Doo&rs", onPasteDoors },
1329
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Layers", onPasteLayers },
1330
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Palette", onPastePalette },
1331 };
1332
1333 enum
1334 {
1335 MENUID_EDIT_UNDO,
1336 MENUID_EDIT_REDO,
1337 MENUID_EDIT_COPY,
1338 MENUID_EDIT_PASTE,
1339 MENUID_EDIT_PASTEALL,
1340 MENUID_EDIT_ADVPASTE,
1341 MENUID_EDIT_SPECPASTE,
1342 MENUID_EDIT_DELETE,
1343 };
1344
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu edit_menu
1345 132 {
1346
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Undo", onUndo, MENUID_EDIT_UNDO },
1347
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Redo", onRedo, MENUID_EDIT_REDO },
1348
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Copy", onCopy, MENUID_EDIT_COPY },
1349
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Paste", onPaste, MENUID_EDIT_PASTE },
1350
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Paste A&ll", onPasteAll, MENUID_EDIT_PASTEALL },
1351
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Adv. Paste ", &paste_menu, MENUID_EDIT_ADVPASTE },
1352
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Paste &Spec. ", &paste_item_menu, MENUID_EDIT_SPECPASTE },
1353
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Delete", onDelete, MENUID_EDIT_DELETE },
1354
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1355
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Maps ", &maps_menu },
1356 };
1357
1358
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu drawing_mode_menu
1359 60 {
1360
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Normal", onDrawingModeNormal, dm_normal },
1361
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combo Alias", onDrawingModeAlias, dm_alias },
1362
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Pool", onDrawingModePool, dm_cpool },
1363
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Auto Combo", onDrawingModeAuto, dm_auto },
1364 };
1365
1366
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu integrity_check_menu
1367 48 {
1368
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&All ", onIntegrityCheckAll },
1369
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Screens ", onIntegrityCheckRooms },
1370
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Warps ", onIntegrityCheckWarps },
1371 };
1372
1373
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu quest_reports_menu
1374 108 {
1375
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Bugged Next-> Combo Locations", onBuggedNextComboLocationReport },
1376
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combo Locations", onComboLocationReport },
1377
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combo Type Locations", onComboTypeLocationReport },
1378
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Enemy Locations", onEnemyLocationReport },
1379
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Item Locations", onItemLocationReport },
1380
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Script Locations", onScriptLocationReport },
1381
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&What Links Here", onWhatWarpsReport },
1382
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "In&tegrity Check ", &integrity_check_menu },
1383 };
1384
1385 int32_t onPalFix();
1386 int32_t onPitFix();
1387 int32_t onStrFix()
1388 {
1389 if(get_qr(qr_OLD_STRING_EDITOR_MARGINS))
1390 {
1391 AlertDialog("Fix: Old Margins",
1392 "Fixing margins may cause strings that used to spill outside the textbox"
1393 " to instead be cut off. Are you sure?",
1394 [&](bool ret,bool)
1395 {
1396 if(ret)
1397 {
1398 set_qr(qr_OLD_STRING_EDITOR_MARGINS, 0);
1399 saved = false;
1400 }
1401 }).show();
1402 }
1403 if(get_qr(qr_STRING_FRAME_OLD_WIDTH_HEIGHT))
1404 {
1405 AlertDialog("Fix: Old Frame Size",
1406 "This will fix the frame size of all strings. No visual changes should occur,"
1407 " as the string width/height will be fixed, but the compat QR will also be unchecked.",
1408 [&](bool ret,bool)
1409 {
1410 if(ret)
1411 {
1412 for(auto q = 0; q < msg_count; ++q)
1413 {
1414 MsgStrings[q].w += 16;
1415 MsgStrings[q].h += 16;
1416 }
1417 set_qr(qr_STRING_FRAME_OLD_WIDTH_HEIGHT, 0);
1418 saved = false;
1419 }
1420 }).show();
1421 }
1422 return D_O_K;
1423 }
1424
1425 int32_t onRemoveOldArrivalSquare();
1426 enum
1427 {
1428 MENUID_FIXTOOL_OLDSTRING,
1429 };
1430
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu fixtools_menu
1431 96 {
1432
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Color Set Fix", onCSetFix },
1433
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Liquid Solidity Fix", onWaterSolidity },
1434
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Effect Square Fix", onEffectFix },
1435
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Level Palette Fix", onPalFix },
1436
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Pit and Liquid Damage Fix", onPitFix },
1437
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Old Strings Fix", onStrFix, MENUID_FIXTOOL_OLDSTRING },
1438
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Green Arrival Square Fix", onRemoveOldArrivalSquare },
1439 };
1440
1441
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu tool_menu
1442 132 {
1443
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Combo &Flags", onFlags, nullopt, MFL_EXIT_PRE_PROC },
1444
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Fix &Tools ", &fixtools_menu },
1445
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&NES Dungeon Template", onTemplate },
1446
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Apply Template to All", onReTemplate },
1447
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1448
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Preview Mode", onPreviewMode },
1449
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Drawing &Mode ", &drawing_mode_menu },
1450
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1451
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&List Combos Used", onUsedCombos },
1452
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Quest Reports ", &quest_reports_menu },
1453 };
1454
1455 int32_t onLayer3BG()
1456 {
1457 ViewLayer3BG = ViewLayer3BG ? 0 : 1;
1458 zc_set_config("zquest","layer3_bg",ViewLayer3BG);
1459 return D_O_K;
1460 }
1461 int32_t onLayer2BG()
1462 {
1463 ViewLayer2BG = ViewLayer2BG ? 0 : 1;
1464 zc_set_config("zquest","layer2_bg",ViewLayer2BG);
1465 return D_O_K;
1466 }
1467 int onGridToggle();
1468 enum
1469 {
1470 MENUID_VIEW_WALKABILITY,
1471 MENUID_VIEW_FLAGS,
1472 MENUID_VIEW_CSET,
1473 MENUID_VIEW_TYPES,
1474 MENUID_VIEW_INFO,
1475 MENUID_VIEW_SQUARES,
1476 MENUID_VIEW_FFCS,
1477 MENUID_VIEW_SCRIPTNAMES,
1478 MENUID_VIEW_GRID,
1479 MENUID_VIEW_SCREENGRID,
1480 MENUID_VIEW_REGIONGRID,
1481 MENUID_VIEW_CURSCROUTLINE,
1482 MENUID_VIEW_DARKNESS,
1483 MENUID_VIEW_L2BG,
1484 MENUID_VIEW_L3BG,
1485 MENUID_VIEW_LAYERHIGHLIGHT,
1486 };
1487
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 NewMenu view_menu
1488 252 {
1489
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "View &Map...", onViewMap },
1490
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "View &Palette", onShowPal },
1491
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1492
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show &Walkability", onShowWalkability, MENUID_VIEW_WALKABILITY },
1493
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show &Flags", onShowFlags, MENUID_VIEW_FLAGS },
1494
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show &CSets", onShowCSet, MENUID_VIEW_CSET },
1495
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show &Types", onShowCType, MENUID_VIEW_TYPES },
1496
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1497
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show Screen &Info", onToggleShowInfo, MENUID_VIEW_INFO },
1498
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show &Squares", onToggleShowSquares, MENUID_VIEW_SQUARES },
1499
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show FFCs", onToggleShowFFCs, MENUID_VIEW_FFCS },
1500
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show Script &Names", onToggleShowScripts, MENUID_VIEW_SCRIPTNAMES },
1501
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show &Grid", onGridToggle, MENUID_VIEW_GRID },
1502
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show Screen G&rid", onToggleScreenGrid, MENUID_VIEW_SCREENGRID },
1503
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show Region Grid", onToggleRegionGrid, MENUID_VIEW_REGIONGRID },
1504
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show Current Screen Outline", onToggleCurrentScreenOutline, MENUID_VIEW_CURSCROUTLINE },
1505
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show &Darkness", onShowDarkness, MENUID_VIEW_DARKNESS },
1506
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Layer 2 is Background", onLayer2BG, MENUID_VIEW_L2BG },
1507
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Layer 3 is Background", onLayer3BG, MENUID_VIEW_L3BG },
1508
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Highlight Current Layer", onToggleHighlightLayer, MENUID_VIEW_LAYERHIGHLIGHT },
1509 };
1510
1511 11 void set_rules(byte* newrules)
1512 {
1513 11 saved = false;
1514
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(newrules != quest_rules)
1515 memcpy(quest_rules, newrules, QR_SZ);
1516 11 unpack_qrs();
1517
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 2 times.
11 if(!get_qr(qr_ALLOW_EDITING_COMBO_0))
1518 {
1519 2 combobuf[0].walk = 0xF0;
1520 2 combobuf[0].type = 0;
1521 2 combobuf[0].flag = 0;
1522 2 }
1523
1524 // For 2.50.0 and 2.50.1
1525
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 2 times.
11 if(get_qr(qr_VERYFASTSCROLLING))
1526 2 set_qr(qr_FASTDNGN, 1);
1527 11 }
1528
1529 int32_t onSelectFFCombo();
1530
1531 void onScreenNotes()
1532 {
1533 edit_screen_notes(Map.CurrScr(), Map.getCurrMap(), Map.getCurrScr());
1534 }
1535
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu data_menu
1536 216 {
1537
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Screen Data", onScrData },
1538
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Freeform Combos", onSelectFFCombo },
1539
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "La&yers", onLayers },
1540
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Tile Warp", onTileWarp },
1541
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Side &Warp", onSideWarp },
1542
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Secret &Combos", onSecretCombo },
1543
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Under Combo", onUnderCombo },
1544
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Doors", onDoors },
1545
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Maze Path", onPath },
1546
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1547
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Item", onItem },
1548
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Enemies", onEnemies },
1549
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Palette", onScreenPalette },
1550
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1551
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Room Data", onRoom },
1552
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Notes", onScreenNotes },
1553
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Browse Notes", browse_screen_notes },
1554 };
1555
1556
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu tunes_menu
1557 252 {
1558
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "ZC Forever", playZCForever },
1559
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Wind Fish", playTune1 },
1560
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Overworld", playTune2 },
1561
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Hyrule Castle", playTune3 },
1562
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Lost Woods", playTune4 },
1563
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Great Sea", playTune5 },
1564
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "East Hyrule", playTune6 },
1565
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Dancing Dragon", playTune7 },
1566
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Stone Tower", playTune8 },
1567
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Villages", playTune9 },
1568
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Swamp + Desert", playTune10 },
1569
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Outset Island", playTune11 },
1570
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Kakariko Village", playTune12 },
1571
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Clock Town", playTune13 },
1572
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Temple", playTune14 },
1573
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Dark World", playTune15 },
1574
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Dragon Roost", playTune16 },
1575
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Horse Race", playTune17 },
1576
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Credits", playTune18 },
1577
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Zelda's Lullaby", playTune19 },
1578 };
1579
1580 enum
1581 {
1582 MENUID_MEDIA_TUNES,
1583 MENUID_MEDIA_PLAYMUSIC,
1584 MENUID_MEDIA_CHANGETRACK,
1585 };
1586
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu media_menu
1587 60 {
1588
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Ambient Music ", &tunes_menu, MENUID_MEDIA_TUNES },
1589
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Play music", playMusic, MENUID_MEDIA_PLAYMUSIC },
1590
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Change track", changeTrack, MENUID_MEDIA_CHANGETRACK },
1591
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Stop tunes", stopMusic },
1592 };
1593
1594 enum
1595 {
1596 MENUID_ETC_VIDMODE,
1597 MENUID_ETC_FULLSCREEN,
1598 MENUID_ETC_DEBUG_CONSOLE,
1599 };
1600
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu etc_menu
1601 192 {
1602
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Help", &zq_help_menu },
1603
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&About", onAbout },
1604
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Video Mode", onZQVidMode, MENUID_ETC_VIDMODE },
1605
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Options...", onOptions },
1606
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Hotkeys...", do_zq_hotkey_dialog },
1607
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&List Hotkeys...", do_zq_list_hotkeys_dialog },
1608
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Fullscreen", onFullScreen, MENUID_ETC_FULLSCREEN },
1609
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1610
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&View Pic...", onViewPic },
1611
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Media", &media_menu },
1612
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1613
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Debug Console", toggleConsole, MENUID_ETC_DEBUG_CONSOLE },
1614
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Clear Quest Filepath", onClearQuestFilepath },
1615
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Take ZQ Snapshot", onMenuSnapshot },
1616
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Take &Screen Snapshot", onMapscrSnapshot },
1617 };
1618
1619
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu zscript_menu
1620 60 {
1621
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Compile &ZScript...", onCompileScript },
1622
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1623
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Compiler Settings", onZScriptCompilerSettings },
1624
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Quest Script Settings", onZScriptSettings },
1625 };
1626
1627 void set_console_state()
1628 {
1629 etc_menu.select_uid(MENUID_ETC_DEBUG_CONSOLE, console_is_open);
1630 }
1631
1632
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 TopMenu the_menu
1633 108 {
1634
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&File", &file_menu },
1635
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Quest", &quest_menu },
1636
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Edit", &edit_menu },
1637
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&View", &view_menu },
1638
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Tools", &tool_menu },
1639
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Screen", &data_menu },
1640
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&ZScript", &zscript_menu },
1641
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Et&C", &etc_menu },
1642 };
1643
1644 void rebuild_trans_table();
1645 int32_t launchPicViewer(BITMAP **pictoview, PALETTE pal,
1646 int32_t *px2, int32_t *py2, double *scale, bool isviewingmap, bool skipmenu = false);
1647
1648 int32_t onResetTransparency()
1649 {
1650 restore_mouse();
1651 rebuild_trans_table();
1652 jwin_alert("Notice","Translucency Table Rebuilt",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
1653
1654 refresh(rALL);
1655 return D_O_K;
1656 }
1657
1658 int32_t onFullScreen()
1659 {
1660 get_palette(RAMpal);
1661 bool windowed=is_windowed_mode()!=0;
1662 all_toggle_fullscreen(windowed);
1663
1664 gui_mouse_focus=0;
1665 gui_bg_color=jwin_pal[jcBOX];
1666 gui_fg_color=jwin_pal[jcBOXFG];
1667 MouseSprite::set(ZQM_NORMAL);
1668 zc_set_palette(RAMpal);
1669 position_mouse(zq_screen_w/2,zq_screen_h/2);
1670 set_display_switch_mode(SWITCH_BACKGROUND);
1671 set_display_switch_callback(SWITCH_OUT, switch_out);
1672 set_display_switch_callback(SWITCH_IN, switch_in);
1673 zc_set_config("zquest","fullscreen", is_windowed_mode() ? 0 : 1);
1674 return D_REDRAW;
1675 }
1676
1677 int32_t onEnter()
1678 {
1679 if(key[KEY_ALT]||key[KEY_ALTGR])
1680 {
1681 return onFullScreen();
1682 }
1683
1684 return D_O_K;
1685 }
1686
1687 //PROC, x, y, w, h, fg, bg, key, flags, d1, d2, *dp, *dp2, *dp3
1688
1689 //*text, (*proc), *child, flags, *dp
1690
1691 void run_zq_frame();
1692 int32_t d_nbmenu_proc(int32_t msg,DIALOG *d,int32_t c);
1693
1694
1695 /*int32_t onY()
1696 {
1697 return D_O_K;
1698 }*/
1699
1700 int32_t onToggleGrid(bool color)
1701 {
1702 if(color)
1703 {
1704 GridColor=(GridColor+8)%16;
1705 zc_set_config("zquest", "grid_color", GridColor);
1706 }
1707 else
1708 {
1709 ShowGrid=!ShowGrid;
1710 zc_set_config("zquest","show_grid",ShowGrid);
1711 }
1712
1713 return D_O_K;
1714 }
1715
1716 int onGridToggle()
1717 {
1718 return onToggleGrid(CHECK_CTRL_CMD);
1719 }
1720
1721 int32_t onToggleScreenGrid()
1722 {
1723 ShowScreenGrid=!ShowScreenGrid;
1724 zc_set_config("zquest","show_screen_grid",ShowScreenGrid);
1725 return D_O_K;
1726 }
1727
1728 int32_t onToggleRegionGrid()
1729 {
1730 ShowRegionGrid=!ShowRegionGrid;
1731 zc_set_config("zquest","show_region_grid",ShowRegionGrid);
1732 return D_O_K;
1733 }
1734
1735 int32_t onToggleCurrentScreenOutline()
1736 {
1737 ShowCurScreenOutline=!ShowCurScreenOutline;
1738 zc_set_config("zquest","show_current_screen_outline",ShowCurScreenOutline);
1739 return D_O_K;
1740 }
1741
1742 int32_t onToggleShowScripts()
1743 {
1744 ShowFFScripts=!ShowFFScripts;
1745 zc_set_config("zquest","showffscripts",ShowFFScripts);
1746 return D_O_K;
1747 }
1748
1749 int32_t onToggleShowFFCs()
1750 {
1751 ShowFFCs=!ShowFFCs;
1752 zc_set_config("zquest","showffcs",ShowFFCs);
1753 return D_O_K;
1754 }
1755
1756 int32_t onToggleShowSquares()
1757 {
1758 ShowSquares=!ShowSquares;
1759 zc_set_config("zquest","showsquares",ShowSquares);
1760 return D_O_K;
1761 }
1762
1763 int32_t onToggleShowInfo()
1764 {
1765 ShowInfo=!ShowInfo;
1766 zc_set_config("zquest","showinfo",ShowInfo);
1767 return D_O_K;
1768 }
1769
1770 int32_t onToggleHighlightLayer()
1771 {
1772 ActiveLayerHighlight = ActiveLayerHighlight ? 0 : 1;
1773 zc_set_config("zquest","hl_active_lyr",ActiveLayerHighlight);
1774 return D_O_K;
1775 }
1776
1777 int onKeySlash()
1778 {
1779 if(key[KEY_LSHIFT] || key[KEY_RSHIFT])
1780 {
1781 onAbout();
1782 }
1783 return D_O_K;
1784 }
1785
1786 int onAKey()
1787 {
1788 if(prv_mode)
1789 Map.set_prvadvance(1);
1790 return D_O_K;
1791 }
1792
1793 int onReloadPreview()
1794 {
1795 if(prv_mode)
1796 {
1797 Map.set_prvscr(Map.get_prv_map(), Map.get_prv_scr());
1798 Map.set_prvcmb(0);
1799 }
1800 return D_O_K;
1801 }
1802 int onSecretsPreview()
1803 {
1804 if(prv_mode)
1805 {
1806 Map.prv_secrets(false);
1807 refresh(rALL);
1808 }
1809 return D_O_K;
1810 }
1811
1812 int onSKey()
1813 {
1814 if(CHECK_CTRL_CMD)
1815 {
1816 if(key[KEY_LSHIFT] || key[KEY_RSHIFT])
1817 {
1818 onSaveAs();
1819 }
1820 else
1821 {
1822 if(!saved)
1823 onSave();
1824 }
1825 }
1826 else if(prv_mode)
1827 {
1828 Map.prv_secrets(false);
1829 refresh(rALL);
1830 }
1831 else onStrings();
1832 return D_O_K;
1833 }
1834 int onSetNewLayer(int newlayer)
1835 {
1836 CurrentLayer = newlayer;
1837 refresh(rALL);
1838 return D_O_K;
1839 }
1840 void lpal_dsa()
1841 {
1842 info_dsa("Level Palette Shortcuts",
1843 "You currently have level palette shortcuts disabled."
1844 " These can be re-enabled in 'Etc->Options', on the toggle 'Disable Level Palette Shortcuts'.",
1845 "dsa_lpal");
1846 }
1847 int onScreenLPal(int lpal)
1848 {
1849 if(DisableLPalShortcuts)
1850 {
1851 lpal_dsa();
1852 return D_O_K;
1853 }
1854 saved=false;
1855 Map.setcolor(lpal);
1856 refresh(rSCRMAP);
1857 return D_O_K;
1858 }
1859
1860 int32_t onPressEsc()
1861 {
1862 if(zoomed_minimap)
1863 mmap_set_zoom(false);
1864 else return onExit();
1865 return D_O_K;
1866 }
1867
1868 static DIALOG dialogs[] =
1869 {
1870 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
1871 { d_nbmenu_proc, 0, 0, 0, 13, 0, 0, 0, D_USER, 0, 0, (void *) &the_menu, NULL, NULL },
1872 { d_zq_hotkey_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
1873
1874 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F1, 0, (void *) onHelp, NULL, NULL },
1875 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_ESC, 0, (void *) onPressEsc, NULL, NULL },
1876 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 39, 0, 0, 0, (void *) onUsedCombos, NULL, NULL },
1877 { d_vsync_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
1878 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
1879 };
1880
1881
1882 int32_t onDecColour()
1883 {
1884 if ( CHECK_CTRL_CMD )
1885 {
1886 return onDecScrPal16();
1887 }
1888
1889 else if ( key[KEY_LSHIFT] || key[KEY_RSHIFT] )
1890 {
1891 return onDecScrPal();
1892 }
1893
1894 else
1895 {
1896 return onDecreaseCSet();
1897 }
1898 }
1899
1900 int32_t onIncColour()
1901 {
1902
1903 if ( CHECK_CTRL_CMD )
1904 {
1905 return onIncScrPal16();
1906 }
1907
1908 else if ( key[KEY_LSHIFT] || key[KEY_RSHIFT] )
1909 {
1910 return onIncScrPal();
1911 }
1912
1913 else
1914 {
1915 return onIncreaseCSet();
1916 }
1917 }
1918
1919 static DIALOG getnum_dlg[] =
1920 {
1921 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
1922 12 { jwin_win_proc, 80, 80, 160, 72, vc(0), vc(11), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
1923 12 { jwin_rtext_proc, 114, 104+4, 48, 8, jwin_pal[jcBOXFG], jwin_pal[jcBOX], 0, 0, 0, 0, (void *) "Value:", NULL, NULL },
1924 12 { jwin_edit_proc, 168, 104, 48, 16, 0, 0, 0, 0, 6, 0, NULL, NULL, NULL },
1925 12 { jwin_button_proc, 90, 126, 61, 21, vc(0), vc(11), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
1926 12 { jwin_button_proc, 170, 126, 61, 21, vc(0), vc(11), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
1927 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
1928 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
1929 };
1930
1931 int32_t getnumber(const char *prompt,int32_t initialval)
1932 {
1933 cancelgetnum=true;
1934 char buf[20];
1935 sprintf(buf,"%d",initialval);
1936 getnum_dlg[0].dp=(void *)prompt;
1937 getnum_dlg[0].dp2=get_zc_font(font_lfont);
1938 getnum_dlg[2].dp=(void *)buf;
1939
1940 large_dialog(getnum_dlg);
1941
1942 int32_t ret=do_zqdialog(getnum_dlg,2);
1943
1944 if(ret!=0&&ret!=4)
1945 {
1946 cancelgetnum=false;
1947 }
1948
1949 if(ret==3)
1950 return atoi(buf);
1951
1952 return initialval;
1953 }
1954
1955 static DIALOG save_tiles_dlg[] =
1956 {
1957 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
1958
1959
1960 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Save Tile Pack", NULL, NULL },
1961 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
1962 //for future tabs
1963 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
1964 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
1965 //4
1966 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "First", NULL, NULL },
1967 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
1968 //6
1969 { jwin_text_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
1970 { jwin_edit_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
1971 //8
1972 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Save", NULL, NULL },
1973 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
1974 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
1975 };
1976
1977
1978 void savesometiles(const char *prompt,int32_t initialval)
1979 {
1980
1981 char firsttile[8], tilecount[8];
1982 int32_t first_tile_id = 0; int32_t the_tile_count = 1;
1983 sprintf(firsttile,"%d",0);
1984 sprintf(tilecount,"%d",1);
1985 //int32_t ret;
1986
1987
1988
1989 save_tiles_dlg[0].dp2 = get_zc_font(font_lfont);
1990
1991 sprintf(firsttile,"%d",0);
1992 sprintf(tilecount,"%d",1);
1993
1994 save_tiles_dlg[5].dp = firsttile;
1995 save_tiles_dlg[7].dp = tilecount;
1996
1997 large_dialog(save_tiles_dlg);
1998
1999 int32_t ret = do_zqdialog(save_tiles_dlg,-1);
2000 jwin_center_dialog(save_tiles_dlg);
2001
2002 if(ret == 8)
2003 {
2004 first_tile_id = vbound(atoi(firsttile), 0, NEWMAXTILES);
2005 the_tile_count = vbound(atoi(tilecount), 1, NEWMAXTILES-first_tile_id);
2006 if(prompt_for_new_file_compat("Save ZTILE(.ztile)", "ztile", NULL,datapath,false))
2007 {
2008 char name[PATH_MAX];
2009 extract_name(temppath,name,FILENAMEALL);
2010 PACKFILE *f=pack_fopen_password(temppath,F_WRITE, "");
2011 if(f)
2012 {
2013 writetilefile(f,first_tile_id,the_tile_count);
2014 pack_fclose(f);
2015 char tmpbuf[PATH_MAX+20]={0};
2016 sprintf(tmpbuf,"Saved %s",name);
2017 jwin_alert("Success!",tmpbuf,NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2018 }
2019 }
2020 }
2021 }
2022
2023 static DIALOG read_tiles_dlg[] =
2024 {
2025 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2026
2027
2028 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Load Tilepack To:", NULL, NULL },
2029 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2030 //for future tabs
2031 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2032 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2033 //4
2034 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Starting at:", NULL, NULL },
2035 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2036 //6
2037 { d_dummy_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2038 { d_dummy_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2039 //8
2040 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Load", NULL, NULL },
2041 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2042 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2043 };
2044
2045
2046 void writesometiles_to(const char *prompt,int32_t initialval)
2047 {
2048
2049 char firsttile[8];;
2050 int32_t first_tile_id = 0; int32_t the_tile_count = 1;
2051 sprintf(firsttile,"%d",0);
2052 //int32_t ret;
2053
2054
2055
2056 read_tiles_dlg[0].dp2 = get_zc_font(font_lfont);
2057
2058 sprintf(firsttile,"%d",0);
2059 //sprintf(tilecount,"%d",1);
2060
2061 read_tiles_dlg[5].dp = firsttile;
2062
2063 large_dialog(read_tiles_dlg);
2064
2065 int32_t ret = do_zqdialog(read_tiles_dlg,-1);
2066 jwin_center_dialog(read_tiles_dlg);
2067
2068 if(ret == 8)
2069 {
2070 first_tile_id = vbound(atoi(firsttile), 0, NEWMAXTILES);
2071 //the_tile_count = vbound(atoi(tilecount), 1, NEWMAXTILES-first_tile_id);
2072 if(prompt_for_existing_file_compat("Load ZTILE(.ztile)", "ztile", NULL,datapath,false))
2073 {
2074
2075 char name[256];
2076 extract_name(temppath,name,FILENAMEALL);
2077 PACKFILE *f=pack_fopen_password(temppath,F_READ, "");
2078 if(f)
2079 {
2080
2081 if (!readtilefile_to_location(f,first_tile_id))
2082 {
2083 al_trace("Could not read from .ztile packfile %s\n", name);
2084 jwin_alert("ZTILE File: Error","Could not load the specified Tile.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2085 }
2086 else
2087 {
2088 jwin_alert("ZTILE File: Success!","Loaded the source tiles to your tile sheets!",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2089 }
2090 pack_fclose(f);
2091 }
2092 }
2093 }
2094 }
2095
2096
2097 static DIALOG save_combofiles_dlg[] =
2098 {
2099 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2100
2101
2102 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Save Combo Pack", NULL, NULL },
2103 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2104 //for future tabs
2105 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2106 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2107 //4
2108 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "First", NULL, NULL },
2109 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2110 //6
2111 { jwin_text_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2112 { jwin_edit_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2113 //8
2114 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Save", NULL, NULL },
2115 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2116 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2117 };
2118
2119
2120 void savesomecombos(const char *prompt,int32_t initialval)
2121 {
2122
2123 char firsttile[8], tilecount[8];
2124 int32_t first_tile_id = 0; int32_t the_tile_count = 1;
2125 sprintf(firsttile,"%d",0);
2126 sprintf(tilecount,"%d",1);
2127 //int32_t ret;
2128
2129
2130
2131 save_combofiles_dlg[0].dp2 = get_zc_font(font_lfont);
2132
2133 sprintf(firsttile,"%d",0);
2134 sprintf(tilecount,"%d",1);
2135
2136 save_combofiles_dlg[5].dp = firsttile;
2137 save_combofiles_dlg[7].dp = tilecount;
2138
2139 large_dialog(save_combofiles_dlg);
2140
2141 int32_t ret = do_zqdialog(save_combofiles_dlg,-1);
2142 jwin_center_dialog(save_combofiles_dlg);
2143
2144 if(ret == 8)
2145 {
2146 first_tile_id = vbound(atoi(firsttile), 0, (MAXCOMBOS-1));
2147 the_tile_count = vbound(atoi(tilecount), 1, (MAXCOMBOS-1)-first_tile_id);
2148 if(prompt_for_new_file_compat("Save ZCOMBO(.zcombo)", "zcombo", NULL,datapath,false))
2149 {
2150 char name[PATH_MAX];
2151 extract_name(temppath,name,FILENAMEALL);
2152 PACKFILE *f=pack_fopen_password(temppath,F_WRITE, "");
2153 if(f)
2154 {
2155 writecombofile(f,first_tile_id,the_tile_count);
2156 pack_fclose(f);
2157 char tmpbuf[PATH_MAX+20]={0};
2158 sprintf(tmpbuf,"Saved %s",name);
2159 jwin_alert("Success!",tmpbuf,NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2160 }
2161 }
2162 }
2163 }
2164
2165
2166 static DIALOG load_comboset_dlg[] =
2167 {
2168 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2169
2170
2171 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Combo Set (Range)", NULL, NULL },
2172 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2173 //for future tabs
2174 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2175 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2176 //4
2177 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "First:", NULL, NULL },
2178 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2179 //6
2180 { d_dummy_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2181 { d_dummy_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2182 //8
2183 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Load", NULL, NULL },
2184 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2185 { jwin_check_proc, 10, 46, 95, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Don't Overwrite", NULL, NULL },
2186
2187 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2188 };
2189
2190 void writesomecombos(const char *prompt,int32_t initialval)
2191 {
2192
2193 char firsttile[8];
2194 int32_t first_tile_id = 0; int32_t the_tile_count = 1;
2195 sprintf(firsttile,"%d",0);
2196 //int32_t ret;
2197
2198
2199
2200 load_comboset_dlg[0].dp2 = get_zc_font(font_lfont);
2201
2202 sprintf(firsttile,"%d",0);
2203 //sprintf(tilecount,"%d",1);
2204
2205 load_comboset_dlg[5].dp = firsttile;
2206
2207 byte nooverwrite = 0;
2208
2209
2210 large_dialog(load_comboset_dlg);
2211
2212 int32_t ret = do_zqdialog(load_comboset_dlg,-1);
2213 jwin_center_dialog(load_comboset_dlg);
2214
2215 if(ret == 8)
2216 {
2217 if (load_comboset_dlg[10].flags & D_SELECTED) nooverwrite = 1;
2218
2219 al_trace("Nooverwrite is: %d\n", nooverwrite);
2220 first_tile_id = vbound(atoi(firsttile), 0, (MAXCOMBOS-1));
2221 //the_tile_count = vbound(atoi(tilecount), 1, NEWMAXTILES-first_tile_id);
2222 if(prompt_for_existing_file_compat("Load ZCOMBO(.zcombo)", "zcombo", NULL,datapath,false))
2223 {
2224 char name[256];
2225 extract_name(temppath,name,FILENAMEALL);
2226 PACKFILE *f=pack_fopen_password(temppath,F_READ, "");
2227 if(f)
2228 {
2229
2230 if (!readcombofile(f,first_tile_id,nooverwrite))
2231 {
2232 al_trace("Could not read from .zcombo packfile %s\n", name);
2233 jwin_alert("ZCOMBO File: Error","Could not load the specified combos.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2234 }
2235 else
2236 {
2237 jwin_alert("ZCOMBO File: Success!","Loaded the source combos to your combo pages!",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2238 saved=false;
2239 }
2240 pack_fclose(f);
2241 }
2242
2243 }
2244 }
2245 }
2246
2247 static DIALOG load_combopack_dlg[] =
2248 {
2249 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2250
2251
2252 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Import Full Combo Package 1:1", NULL, NULL },
2253 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2254 //for future tabs
2255 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2256 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2257 //4
2258 { d_dummy_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Starting at:", NULL, NULL },
2259 { d_dummy_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2260 //6
2261 { d_dummy_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2262 { d_dummy_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2263 //8
2264 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Load", NULL, NULL },
2265 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2266 { jwin_check_proc, 10, 42, 95, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Don't Overwrite", NULL, NULL },
2267
2268 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2269 };
2270
2271 void loadcombopack(const char *prompt,int32_t initialval)
2272 {
2273
2274 char firsttile[8];
2275 int32_t first_tile_id = 0; int32_t the_tile_count = 1;
2276 sprintf(firsttile,"%d",0);
2277 //int32_t ret;
2278
2279
2280
2281 load_combopack_dlg[0].dp2 = get_zc_font(font_lfont);
2282
2283 sprintf(firsttile,"%d",0);
2284 //sprintf(tilecount,"%d",1);
2285
2286 load_combopack_dlg[5].dp = firsttile;
2287
2288 byte nooverwrite = 0;
2289
2290
2291 large_dialog(load_combopack_dlg);
2292
2293 int32_t ret = do_zqdialog(load_combopack_dlg,-1);
2294 jwin_center_dialog(load_combopack_dlg);
2295
2296 if(ret == 8)
2297 {
2298 if (load_combopack_dlg[10].flags & D_SELECTED) nooverwrite = 1;
2299
2300 al_trace("Nooverwrite is: %d\n", nooverwrite);
2301 first_tile_id = vbound(atoi(firsttile), 0, (MAXCOMBOS-1));
2302 //the_tile_count = vbound(atoi(tilecount), 1, NEWMAXTILES-first_tile_id);
2303 if(prompt_for_existing_file_compat("Load ZCOMBO(.zcombo)", "zcombo", NULL,datapath,false))
2304 {
2305 char name[256];
2306 extract_name(temppath,name,FILENAMEALL);
2307 PACKFILE *f=pack_fopen_password(temppath,F_READ, "");
2308 if(f)
2309 {
2310 //need dialogue here
2311 if (!readcombofile(f,0,nooverwrite))
2312 {
2313 al_trace("Could not read from .zcombo packfile %s\n", name);
2314 jwin_alert("ZCOMBO File: Error","Could not load the specified Tile.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2315 }
2316 else
2317 {
2318 jwin_alert("ZCOMBO File: Success!","Loaded the source combos to your combo pages!",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2319 saved=false;
2320 }
2321 }
2322
2323 pack_fclose(f);
2324 }
2325 }
2326 }
2327
2328
2329 static DIALOG read_combopack_dlg[] =
2330 {
2331 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2332
2333
2334 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Load Combos (Specific Dest)", NULL, NULL },
2335 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2336 //for future tabs
2337 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2338 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2339 //4
2340 { jwin_text_proc, 10, 24, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Starting at:", NULL, NULL },
2341 { jwin_edit_proc, 55, 22, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2342 //6
2343 { d_dummy_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2344 { d_dummy_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2345 //8
2346 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Load", NULL, NULL },
2347 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2348 //10
2349 { jwin_check_proc, 10, 58, 95, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Don't Overwrite", NULL, NULL },
2350 //11
2351 { jwin_text_proc, 10, 42, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Skip:", NULL, NULL },
2352 //12
2353 { jwin_edit_proc, 55, 40, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2354
2355 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2356 };
2357
2358
2359
2360 void writesomecombos_to(const char *prompt,int32_t initialval)
2361 {
2362
2363 char firsttile[8];
2364 char skiptile[8];
2365 int32_t first_tile_id = 0; int32_t the_tile_count = 1;
2366 sprintf(firsttile,"%d",0);
2367 //int32_t ret;
2368
2369
2370
2371 read_combopack_dlg[0].dp2 = get_zc_font(font_lfont);
2372
2373 sprintf(skiptile,"%d",0);
2374 //sprintf(tilecount,"%d",1);
2375
2376 read_combopack_dlg[5].dp = firsttile;
2377
2378 byte nooverwrite = 0;
2379 int32_t skipover = 0;
2380
2381 sprintf(skiptile,"%d",0);
2382 //sprintf(tilecount,"%d",1);
2383
2384 read_combopack_dlg[12].dp = skiptile;
2385
2386 large_dialog(read_combopack_dlg);
2387
2388 int32_t ret = do_zqdialog(read_combopack_dlg,-1);
2389 jwin_center_dialog(read_combopack_dlg);
2390
2391 if(ret == 8)
2392 {
2393 if (read_combopack_dlg[10].flags & D_SELECTED) nooverwrite = 1;
2394
2395 first_tile_id = vbound(atoi(firsttile), 0, (MAXCOMBOS-1));
2396 skipover = vbound(atoi(skiptile), 0, (MAXCOMBOS-1));
2397 al_trace("skipover is: %d\n", skipover);
2398 //skipover = vbound(skipover, 0, (MAXCOMBOS-1-skipover));
2399 //the_tile_count = vbound(atoi(tilecount), 1, NEWMAXTILES-first_tile_id);
2400 if(prompt_for_existing_file_compat("Load ZCOMBO(.zcombo)", "zcombo", NULL,datapath,false))
2401 {
2402 char name[256];
2403 extract_name(temppath,name,FILENAMEALL);
2404 PACKFILE *f=pack_fopen_password(temppath,F_READ, "");
2405 if(f)
2406 {
2407
2408 if (!readcombofile_to_location(f,first_tile_id,nooverwrite, skipover))
2409 {
2410 al_trace("Could not read from .zcombo packfile %s\n", name);
2411 jwin_alert("ZCOMBO File: Error","Could not load the specified combos.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2412 }
2413 else
2414 {
2415 jwin_alert("ZCOMBO File: Success!","Loaded the source combos to your combo pages!",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2416 saved=false;
2417 }
2418 pack_fclose(f);
2419 }
2420
2421 }
2422 }
2423 }
2424
2425
2426
2427 static DIALOG save_dmaps_dlg[] =
2428 {
2429 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2430
2431
2432 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Save DMaps (.zdmap)", NULL, NULL },
2433 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2434 //for future tabs
2435 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2436 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2437 //4
2438 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "First", NULL, NULL },
2439 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2440 //6
2441 { jwin_text_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Last", NULL, NULL },
2442 { jwin_edit_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2443 //8
2444 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Save", NULL, NULL },
2445 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2446 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2447 };
2448
2449
2450 void savesomedmaps(const char *prompt,int32_t initialval)
2451 {
2452
2453 char firstdmap[8], lastdmap[8];
2454 int32_t first_dmap_id = 0; int32_t last_dmap_id = 0;
2455 sprintf(firstdmap,"%d",0);
2456 sprintf(lastdmap,"%d",1);
2457 //int32_t ret;
2458
2459
2460
2461 save_dmaps_dlg[0].dp2 = get_zc_font(font_lfont);
2462
2463 sprintf(firstdmap,"%d",0);
2464 sprintf(lastdmap,"%d",0);
2465
2466 save_dmaps_dlg[5].dp = firstdmap;
2467 save_dmaps_dlg[7].dp = lastdmap;
2468
2469 large_dialog(save_dmaps_dlg);
2470
2471 int32_t ret = do_zqdialog(save_dmaps_dlg,-1);
2472 jwin_center_dialog(save_dmaps_dlg);
2473
2474 if(ret == 8)
2475 {
2476 first_dmap_id = vbound(atoi(firstdmap), 0, MAXDMAPS-1);
2477 last_dmap_id = vbound(atoi(lastdmap), 0, MAXDMAPS-1);
2478
2479 if ( last_dmap_id < first_dmap_id )
2480 {
2481 int32_t swap = last_dmap_id;
2482 last_dmap_id = first_dmap_id;
2483 first_dmap_id = swap;
2484 }
2485 if(!prompt_for_new_file_compat("Export DMaps (.zdmap)","zdmap",NULL,datapath,false))
2486
2487
2488 saved=false;
2489
2490 PACKFILE *f=pack_fopen_password(temppath,F_WRITE, "");
2491 if(f)
2492 {
2493 if(!writesomedmaps(f,first_dmap_id,last_dmap_id,MAXDMAPS))
2494 {
2495 char buf[PATH_MAX+20],name[PATH_MAX];
2496 extract_name(temppath,name,FILENAMEALL);
2497 sprintf(buf,"Unable to load %s",name);
2498 jwin_alert("Error",buf,NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2499 }
2500 else
2501 {
2502 char name[PATH_MAX];
2503 extract_name(temppath,name,FILENAMEALL);
2504 char tmpbuf[PATH_MAX+20]={0};
2505 sprintf(tmpbuf,"Saved %s",name);
2506 jwin_alert("Success!",tmpbuf,NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2507 }
2508 }
2509 pack_fclose(f);
2510 }
2511 }
2512
2513 static DIALOG save_comboaliasfiles_dlg[] =
2514 {
2515 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2516
2517
2518 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Save Combo Alias Pack", NULL, NULL },
2519 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2520 //for future tabs
2521 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2522 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2523 //4
2524 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "First", NULL, NULL },
2525 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2526 //6
2527 { jwin_text_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2528 { jwin_edit_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2529 //8
2530 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Save", NULL, NULL },
2531 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2532 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2533 };
2534
2535
2536 void savesomecomboaliases(const char *prompt,int32_t initialval)
2537 {
2538
2539 char firsttile[8], tilecount[8];
2540 int32_t first_tile_id = 0; int32_t the_tile_count = 1;
2541 sprintf(firsttile,"%d",0);
2542 sprintf(tilecount,"%d",1);
2543 //int32_t ret;
2544
2545
2546
2547 save_comboaliasfiles_dlg[0].dp2 = get_zc_font(font_lfont);
2548
2549 sprintf(firsttile,"%d",0);
2550 sprintf(tilecount,"%d",1);
2551
2552 save_comboaliasfiles_dlg[5].dp = firsttile;
2553 save_comboaliasfiles_dlg[7].dp = tilecount;
2554
2555 large_dialog(save_comboaliasfiles_dlg);
2556
2557 int32_t ret = do_zqdialog(save_comboaliasfiles_dlg,-1);
2558 jwin_center_dialog(save_comboaliasfiles_dlg);
2559
2560 if(ret == 8)
2561 {
2562 first_tile_id = vbound(atoi(firsttile), 0, (MAXCOMBOALIASES-1));
2563 the_tile_count = vbound(atoi(tilecount), 1, (MAXCOMBOALIASES-1)-first_tile_id);
2564 if(prompt_for_new_file_compat("Save ZALIAS(.zalias)", "zalias", NULL,datapath,false))
2565 {
2566 char name[PATH_MAX];
2567 extract_name(temppath,name,FILENAMEALL);
2568 PACKFILE *f=pack_fopen_password(temppath,F_WRITE, "");
2569 if(f)
2570 {
2571 writecomboaliasfile(f,first_tile_id,the_tile_count);
2572 pack_fclose(f);
2573 char tmpbuf[PATH_MAX+20]={0};
2574 sprintf(tmpbuf,"Saved %s",name);
2575 jwin_alert("Success!",tmpbuf,NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2576 }
2577 }
2578 }
2579 }
2580
2581
2582 static DIALOG read_comboaliaspack_dlg[] =
2583 {
2584 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2585
2586
2587 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Load Combo Pack To:", NULL, NULL },
2588 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2589 //for future tabs
2590 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2591 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2592 //4
2593 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Starting at:", NULL, NULL },
2594 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2595 //6
2596 { d_dummy_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2597 { d_dummy_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2598 //8
2599 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Load", NULL, NULL },
2600 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2601 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2602 };
2603
2604
2605 void writesomecomboaliases_to(const char *prompt,int32_t initialval)
2606 {
2607
2608 char firsttile[8];;
2609 int32_t first_tile_id = 0; int32_t the_tile_count = 1;
2610 sprintf(firsttile,"%d",0);
2611 //int32_t ret;
2612
2613
2614
2615 read_comboaliaspack_dlg[0].dp2 = get_zc_font(font_lfont);
2616
2617 sprintf(firsttile,"%d",0);
2618 //sprintf(tilecount,"%d",1);
2619
2620 read_comboaliaspack_dlg[5].dp = firsttile;
2621
2622 large_dialog(read_comboaliaspack_dlg);
2623
2624 int32_t ret = do_zqdialog(read_comboaliaspack_dlg,-1);
2625 jwin_center_dialog(read_comboaliaspack_dlg);
2626
2627 if(ret == 8)
2628 {
2629 first_tile_id = vbound(atoi(firsttile), 0, (MAXCOMBOALIASES-1));
2630 //the_tile_count = vbound(atoi(tilecount), 1, NEWMAXTILES-first_tile_id);
2631 if(prompt_for_existing_file_compat("Load ZALIAS(.zalias)", "zalias", NULL,datapath,false))
2632 {
2633 char name[256];
2634 extract_name(temppath,name,FILENAMEALL);
2635 PACKFILE *f=pack_fopen_password(temppath,F_READ, "");
2636 if(f)
2637 {
2638
2639 if (!readcomboaliasfile_to_location(f,first_tile_id))
2640 {
2641 al_trace("Could not read from .zcombo packfile %s\n", name);
2642 jwin_alert("ZALIAS File: Error","Could not load the specified combo aliases.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2643 }
2644 else
2645 {
2646 jwin_alert("ZALIAS File: Success!","Loaded the source combos to your combo alias table!",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2647 saved=false;
2648 }
2649 pack_fclose(f);
2650 }
2651 }
2652 }
2653 }
2654
2655
2656
2657
2658 //Doorsets
2659
2660 static DIALOG save_doorset_dlg[] =
2661 {
2662 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2663 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Save Doorset", NULL, NULL },
2664 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2665 //for future tabs
2666 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2667 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2668 //4
2669 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "First", NULL, NULL },
2670 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2671 //6
2672 { jwin_text_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2673 { jwin_edit_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2674 //8
2675 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Save", NULL, NULL },
2676 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2677 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2678 };
2679
2680
2681 void do_exportdoorset(const char *prompt,int32_t initialval)
2682 {
2683 char firstdoor[8], doorct[8];
2684 int32_t first_doorset_id = 0; int32_t the_doorset_count = 1;
2685 sprintf(firstdoor,"%d",0);
2686 sprintf(doorct,"%d",1);
2687 //int32_t ret;
2688 save_doorset_dlg[0].dp2 = get_zc_font(font_lfont);
2689
2690 sprintf(firstdoor,"%d",0);
2691 sprintf(doorct,"%d",1);
2692
2693 save_doorset_dlg[5].dp = firstdoor;
2694 save_doorset_dlg[7].dp = doorct;
2695
2696 large_dialog(save_doorset_dlg);
2697
2698 int32_t ret = do_zqdialog(save_doorset_dlg,-1);
2699 jwin_center_dialog(save_doorset_dlg);
2700
2701 if(ret == 8) //OK
2702 {
2703 /* sanity bounds
2704 first_doorset_id = vbound(atoi(firstdoor), 0, (MAXCOMBOS-1));
2705 the_doorset_count = vbound(atoi(doorct), 1, (MAXCOMBOS-1)-first_doorset_id);
2706 */
2707 if(prompt_for_new_file_compat("Save ZDOORS(.zdoors)", "zdoors", NULL,datapath,false))
2708 {
2709 char name[256];
2710 extract_name(temppath,name,FILENAMEALL);
2711 PACKFILE *f=pack_fopen_password(temppath,F_WRITE, "");
2712 if(f)
2713 {
2714 writezdoorsets(f,first_doorset_id,the_doorset_count);
2715 pack_fclose(f);
2716 char tmpbuf[512]={0};
2717 sprintf(tmpbuf,"Saved %s",name);
2718 jwin_alert("Success!",tmpbuf,NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2719 }
2720 }
2721 }
2722 }
2723
2724 static DIALOG load_doorset_dlg[] =
2725 {
2726 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2727 { jwin_win_proc, 0, 0, 120, 124, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Door Set (Range)", NULL, NULL },
2728 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2729 //for future tabs
2730 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2731 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2732 //4
2733 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "First:", NULL, NULL },
2734 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2735 //6
2736 { jwin_text_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2737 { jwin_edit_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2738 //8
2739 { jwin_button_proc, 15, 92, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Load", NULL, NULL },
2740 { jwin_button_proc, 69, 92, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2741 //10
2742 { jwin_text_proc, 10, 64, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Dest", NULL, NULL },
2743 { jwin_edit_proc, 55, 63, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2744 //8
2745
2746 // { jwin_check_proc, 10, 46, 95, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Don't Overwrite", NULL, NULL },
2747
2748 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2749 };
2750
2751 void do_importdoorset(const char *prompt,int32_t initialval)
2752 {
2753
2754 char firstdoor[8], doorct[8], destid[8];
2755 int32_t first_doorset_id = 0; int32_t the_doorset_count = 1;
2756 int32_t the_dest_id = 0;
2757 sprintf(firstdoor,"%d",0);
2758 sprintf(doorct,"%d",1);
2759 sprintf(destid,"%d",0);
2760 //int32_t ret;
2761
2762 save_doorset_dlg[0].dp2 = get_zc_font(font_lfont);
2763
2764 load_doorset_dlg[5].dp = firstdoor;
2765 load_doorset_dlg[7].dp = doorct;
2766 load_doorset_dlg[11].dp = destid;
2767
2768 byte nooverwrite = 0;
2769
2770 large_dialog(load_doorset_dlg);
2771
2772 int32_t ret = do_zqdialog(load_doorset_dlg,-1);
2773 jwin_center_dialog(load_doorset_dlg);
2774
2775 if(ret == 8) //OK
2776 {
2777 //if (load_doorset_dlg[10].flags & D_SELECTED) nooverwrite = 1;
2778
2779 //sanity bound
2780 first_doorset_id = vbound(atoi(firstdoor), 0, door_combo_set_count);
2781 the_doorset_count = vbound(atoi(doorct), 1, door_combo_set_count);
2782 the_dest_id = vbound(atoi(destid), 0, door_combo_set_count);
2783 if(prompt_for_existing_file_compat("Load ZDOORS(.zdoors)", "zdoors", NULL,datapath,false))
2784 {
2785 char name[256];
2786 extract_name(temppath,name,FILENAMEALL);
2787 PACKFILE *f=pack_fopen_password(temppath,F_READ, "");
2788 if(f)
2789 {
2790 int32_t ret = readzdoorsets(f,first_doorset_id,the_doorset_count, the_dest_id);
2791
2792 if (!ret)
2793 {
2794 al_trace("Could not read from .zdoors packfile %s\n", name);
2795 jwin_alert("ZDOORS File: Error","Could not load the specified doorsets.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2796 }
2797 else if ( ret == 1 )
2798 {
2799 jwin_alert("ZDOORS File: Success!","Loaded the source doorsets!",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2800 saved=false;
2801 }
2802 else if ( ret == 2 )
2803 {
2804 jwin_alert("ZDOORS File: Issue:","Targets exceed doorset count!",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2805 saved=false;
2806 }
2807 pack_fclose(f);
2808 }
2809 }
2810 }
2811 }
2812
2813 int32_t gettilepagenumber(const char *prompt, int32_t initialval)
2814 {
2815 char buf[20];
2816 sprintf(buf,"%d",initialval);
2817 getnum_dlg[0].dp=(void *)prompt;
2818 getnum_dlg[0].dp2=get_zc_font(font_lfont);
2819 getnum_dlg[2].dp=buf;
2820
2821 large_dialog(getnum_dlg);
2822
2823 int32_t ret = do_zqdialog(getnum_dlg,2);
2824
2825 if(ret==3)
2826 return atoi(buf);
2827
2828 return -1;
2829 }
2830
2831 int32_t gethexnumber(const char *prompt,int32_t initialval)
2832 {
2833 cancelgetnum=true;
2834 char buf[20];
2835 sprintf(buf,"%X",initialval);
2836 getnum_dlg[0].dp=(void *)prompt;
2837 getnum_dlg[0].dp2=get_zc_font(font_lfont);
2838 getnum_dlg[2].dp=(void *)buf;
2839
2840 large_dialog(getnum_dlg);
2841
2842 int32_t ret=do_zqdialog(getnum_dlg,2);
2843
2844 if(ret!=0&&ret!=4)
2845 {
2846 cancelgetnum=false;
2847 }
2848
2849 if(ret==3)
2850 return zc_xtoi(buf);
2851
2852 return initialval;
2853 }
2854
2855 void update_combo_cycling()
2856 {
2857 Map.update_combo_cycling();
2858 }
2859
2860 void update_freeform_combos()
2861 {
2862 Map.update_freeform_combos();
2863 }
2864
2865 bool layers_valid(mapscr *tempscr)
2866 {
2867 for(int32_t i=0; i<6; i++)
2868 {
2869 if(tempscr->layermap[i]>map_count)
2870 {
2871 return false;
2872 }
2873 }
2874
2875 return true;
2876 }
2877
2878 void fix_layers(mapscr *tempscr, bool showwarning)
2879 {
2880 char buf[80]="layers have been changed: ";
2881
2882 for(int32_t i=0; i<6; i++)
2883 {
2884 if(tempscr->layermap[i]>map_count)
2885 {
2886 strcat(buf, "%d ");
2887 sprintf(buf, buf, i+1);
2888 tempscr->layermap[i]=0;
2889 }
2890 }
2891
2892 if(showwarning)
2893 {
2894 jwin_alert("Invalid layers detected",
2895 "One or more layers on this screen used",
2896 "maps that do not exist. The settings of these",
2897 buf, "O&K", NULL, 'o', 0, get_zc_font(font_lfont));
2898 }
2899 }
2900
2901 extern const char *colorlist(int32_t index, int32_t *list_size);
2902
2903 static char autobackup_str_buf[32];
2904 const char *autobackuplist(int32_t index, int32_t *list_size)
2905 {
2906 if(index>=0)
2907 {
2908 bound(index,0,10);
2909
2910 if(index==0)
2911 {
2912 sprintf(autobackup_str_buf,"Disabled");
2913 }
2914 else
2915 {
2916 sprintf(autobackup_str_buf,"%2d",index);
2917 }
2918
2919 return autobackup_str_buf;
2920 }
2921
2922 *list_size=11;
2923 return NULL;
2924 }
2925
2926 static char autosave_str_buf[32];
2927 const char *autosavelist(int32_t index, int32_t *list_size)
2928 {
2929 if(index>=0)
2930 {
2931 bound(index,0,10);
2932
2933 if(index==0)
2934 {
2935 sprintf(autosave_str_buf,"Disabled");
2936 }
2937 else
2938 {
2939 sprintf(autosave_str_buf,"%2d Minute%c",index,index>1?'s':0);
2940 }
2941
2942 return autosave_str_buf;
2943 }
2944
2945 *list_size=11;
2946 return NULL;
2947 }
2948
2949 const char *autosavelist2(int32_t index, int32_t *list_size)
2950 {
2951 if(index>=0)
2952 {
2953 bound(index,0,9);
2954 sprintf(autosave_str_buf,"%2d",index+1);
2955 return autosave_str_buf;
2956 }
2957
2958 *list_size=10;
2959 return NULL;
2960 }
2961
2962
2963 static int32_t options_1_list[] =
2964 {
2965 // dialog control number
2966 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, -1
2967 };
2968
2969 static int32_t options_2_list[] =
2970 {
2971 // dialog control number
2972 50, 51, -1
2973 };
2974
2975 static int32_t options_3_list[] =
2976 {
2977 // dialog control number
2978 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, -1
2979 };
2980 static int32_t options_4_list[] =
2981 {
2982 57, 58, 59, 60,
2983 -1
2984 };
2985
2986 static TABPANEL options_tabs[] =
2987 {
2988 // (text)
2989 { (char *)" 1 ", D_SELECTED, options_1_list, 0, NULL },
2990 { (char *)" 2 ", 0, options_2_list, 0, NULL },
2991 { (char *)" 3 ", 0, options_3_list, 0, NULL },
2992 { (char *)" 4 ", 0, options_4_list, 0, NULL },
2993 { NULL, 0, NULL, 0, NULL }
2994 };
2995
2996 12 static ListData autobackup_list(autobackuplist, &font);
2997 12 static ListData autosave_list(autosavelist, &font);
2998 12 static ListData autosave_list2(autosavelist2, &font);
2999 12 static ListData color_list(colorlist, &font);
3000 12 static ListData snapshotformat_list(snapshotformatlist, &font);
3001
3002 const char *dm_names[dm_max]=
3003 {
3004 "Normal",
3005 "Relational", // Removed.
3006 "Dungeon", // Removed.
3007 "Alias",
3008 "Pool",
3009 "Auto"
3010 };
3011
3012 void fix_drawing_mode_menu()
3013 {
3014 drawing_mode_menu.select_only_uid(draw_mode);
3015 }
3016
3017 int32_t onDrawingMode()
3018 {
3019 draw_mode=(draw_mode+1)%dm_max;
3020 int dm_relational = 1;
3021 if ((int)draw_mode == dm_relational)
3022 draw_mode += 2;
3023 fix_drawing_mode_menu();
3024 restore_mouse();
3025 return D_O_K;
3026 }
3027
3028 int32_t onDrawingModeNormal()
3029 {
3030 draw_mode=dm_normal;
3031 fix_drawing_mode_menu();
3032 restore_mouse();
3033 return D_O_K;
3034 }
3035
3036 int32_t onDrawingModeAlias()
3037 {
3038 if(draw_mode==dm_alias)
3039 {
3040 return onDrawingModeNormal();
3041 }
3042
3043 draw_mode=dm_alias;
3044 alias_cset_mod=0;
3045 fix_drawing_mode_menu();
3046 restore_mouse();
3047 return D_O_K;
3048 }
3049
3050 int32_t onDrawingModePool()
3051 {
3052 if(draw_mode==dm_cpool)
3053 {
3054 return onDrawingModeNormal();
3055 }
3056
3057 draw_mode=dm_cpool;
3058 fix_drawing_mode_menu();
3059 restore_mouse();
3060 return D_O_K;
3061 }
3062
3063 int32_t onDrawingModeAuto()
3064 {
3065 if (draw_mode == dm_auto)
3066 {
3067 return onDrawingModeNormal();
3068 }
3069
3070 draw_mode = dm_auto;
3071 fix_drawing_mode_menu();
3072 restore_mouse();
3073 return D_O_K;
3074 }
3075
3076 int32_t onReTemplate()
3077 {
3078 if(jwin_alert("Confirm Overwrite","Apply NES Dungeon template to","all screens on this map?",NULL,"&Yes","&No",'y','n',get_zc_font(font_lfont))==1)
3079 {
3080 Map.TemplateAll();
3081 refresh(rALL);
3082 }
3083
3084 return D_O_K;
3085 }
3086
3087 int32_t onUndo()
3088 {
3089 Map.UndoCommand();
3090 refresh(rALL);
3091 return D_O_K;
3092 }
3093
3094 int32_t onRedo()
3095 {
3096 Map.RedoCommand();
3097 refresh(rALL);
3098 return D_O_K;
3099 }
3100
3101 int32_t onCopy()
3102 {
3103 if(prv_mode)
3104 {
3105 Map.set_prvcmb(Map.get_prvcmb()==0?1:0);
3106 return D_O_K;
3107 }
3108
3109 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3110 Map.Copy(screen);
3111 return D_O_K;
3112 }
3113
3114 int32_t onPaste()
3115 {
3116 if(key[KEY_LSHIFT] || key[KEY_RSHIFT])
3117 {
3118 if(CHECK_CTRL_CMD)
3119 return onPasteAllToAll();
3120 else return onPasteAll();
3121 }
3122 else if(CHECK_CTRL_CMD)
3123 return onPasteToAll();
3124 else
3125 {
3126 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3127 Map.DoPasteScreenCommand(PasteCommandType::ScreenPartial, screen);
3128 }
3129 return D_O_K;
3130 }
3131
3132 int32_t onPasteAll()
3133 {
3134 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3135 Map.DoPasteScreenCommand(PasteCommandType::ScreenAll, screen);
3136 return D_O_K;
3137 }
3138
3139 int32_t onPasteToAll()
3140 {
3141 if(confirmBox("You are about to paste to all screens on the current map."))
3142 {
3143 Map.DoPasteScreenCommand(PasteCommandType::ScreenPartialToEveryScreen);
3144 }
3145 return D_O_K;
3146 }
3147
3148 int32_t onPasteAllToAll()
3149 {
3150 if(confirmBox("You are about to paste to all screens on the current map."))
3151 {
3152 Map.DoPasteScreenCommand(PasteCommandType::ScreenAllToEveryScreen);
3153 }
3154 return D_O_K;
3155 }
3156
3157 int32_t onPasteUnderCombo()
3158 {
3159 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3160 Map.DoPasteScreenCommand(PasteCommandType::ScreenUnderCombo, screen);
3161 return D_O_K;
3162 }
3163
3164 int32_t onPasteSecretCombos()
3165 {
3166 Map.DoPasteScreenCommand(PasteCommandType::ScreenSecretCombos);
3167 return D_O_K;
3168 }
3169
3170 int32_t onPasteFFCombos()
3171 {
3172 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3173 Map.DoPasteScreenCommand(PasteCommandType::ScreenFFCombos, screen);
3174 return D_O_K;
3175 }
3176
3177 int32_t onPasteWarps()
3178 {
3179 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3180 Map.DoPasteScreenCommand(PasteCommandType::ScreenWarps, screen);
3181 return D_O_K;
3182 }
3183
3184 int32_t onPasteScreenData()
3185 {
3186 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3187 Map.DoPasteScreenCommand(PasteCommandType::ScreenData, screen);
3188 return D_O_K;
3189 }
3190
3191 int32_t onPasteWarpLocations()
3192 {
3193 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3194 Map.DoPasteScreenCommand(PasteCommandType::ScreenWarpLocations, screen);
3195 return D_O_K;
3196 }
3197
3198 int32_t onPasteDoors()
3199 {
3200 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3201 Map.DoPasteScreenCommand(PasteCommandType::ScreenDoors, screen);
3202 return D_O_K;
3203 }
3204
3205 int32_t onPasteLayers()
3206 {
3207 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3208 Map.DoPasteScreenCommand(PasteCommandType::ScreenLayers, screen);
3209 return D_O_K;
3210 }
3211
3212 int32_t onPastePalette()
3213 {
3214 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3215 Map.DoPasteScreenCommand(PasteCommandType::ScreenPalette, screen);
3216 return D_O_K;
3217 }
3218
3219 int32_t onPasteRoom()
3220 {
3221 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3222 Map.DoPasteScreenCommand(PasteCommandType::ScreenRoom, screen);
3223 return D_O_K;
3224 }
3225
3226 int32_t onPasteGuy()
3227 {
3228 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3229 Map.DoPasteScreenCommand(PasteCommandType::ScreenGuy, screen);
3230 return D_O_K;
3231 }
3232
3233 int32_t onPasteEnemies()
3234 {
3235 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3236 Map.DoPasteScreenCommand(PasteCommandType::ScreenEnemies, screen);
3237 return D_O_K;
3238 }
3239
3240 int32_t onDelete()
3241 {
3242 restore_mouse();
3243
3244 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3245 mapscr* scr = active_visible_screen ? active_visible_screen->scr : Map.CurrScr();
3246 if(!(scr->valid&mVALID) || jwin_alert("Confirm Delete","Delete this screen?", NULL, NULL, "Yes", "Cancel", 'y', 27,get_zc_font(font_lfont)) == 1)
3247 {
3248 Map.DoClearScreenCommand(screen);
3249 }
3250
3251 saved=false;
3252 return D_O_K;
3253 }
3254
3255 int32_t onDeleteMap()
3256 {
3257 if(jwin_alert("Confirm Delete","Clear this entire map?", NULL, NULL, "Yes", "Cancel", 'y', 27,get_zc_font(font_lfont)) == 1)
3258 {
3259 Map.clearmap(false);
3260 refresh(rALL);
3261 saved=false;
3262 }
3263
3264 return D_O_K;
3265 }
3266
3267 int32_t onToggleDarkness()
3268 {
3269 Map.CurrScr()->flags^=4;
3270 refresh(rMAP+rMENU);
3271 saved=false;
3272 return D_O_K;
3273 }
3274
3275 int32_t onIncMap()
3276 {
3277 int32_t m=Map.getCurrMap();
3278 Map.setCurrMap(m+1>=map_count?0:m+1);
3279 Map.setlayertarget(); //Needed to refresh the screen info. -Z ( 26th March, 2019 )
3280
3281 refresh(rALL);
3282 return D_O_K;
3283 }
3284
3285 int32_t onDecMap()
3286 {
3287 int32_t m = Map.getCurrMap();
3288 Map.setCurrMap((m-1<0)?map_count-1:zc_min(m-1,map_count-1));
3289 // Map.setCurrScr(Map.getCurrScr()); //Needed to refresh the screen info. -Z ( 26th March, 2019 )
3290 Map.setlayertarget(); //Needed to refresh the screen info. -Z ( 26th March, 2019 )
3291
3292 Map.refresh_color();
3293
3294 refresh(rALL);
3295 return D_O_K;
3296 }
3297
3298
3299 int32_t onDefault_Pals()
3300 {
3301 if(jwin_alert("Confirm Reset","Reset all palette data?", NULL, NULL, "Yes", "Cancel", 'y', 27,get_zc_font(font_lfont)) == 1)
3302 {
3303 saved=false;
3304
3305 if(!init_colordata(true, &header, &QMisc))
3306 {
3307 jwin_alert("Error","Palette reset failed.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
3308 }
3309
3310 refresh_pal();
3311 }
3312
3313 return D_O_K;
3314 }
3315
3316 int32_t onDefault_Combos()
3317 {
3318 if(jwin_alert("Confirm Reset","Reset combo data?", NULL, NULL, "Yes", "Cancel", 'y', 27,get_zc_font(font_lfont)) == 1)
3319 {
3320 saved=false;
3321
3322 if(!init_combos(true, &header))
3323 {
3324 jwin_alert("Error","Combo reset failed.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
3325 }
3326
3327 refresh(rALL);
3328 }
3329
3330 return D_O_K;
3331 }
3332
3333 int32_t onDefault_Items()
3334 {
3335 if(jwin_alert("Confirm Reset","Reset all items?", NULL, NULL, "Yes", "Cancel", 'y', 27,get_zc_font(font_lfont)) == 1)
3336 {
3337 saved=false;
3338 reset_items(true, &header);
3339 }
3340
3341 return D_O_K;
3342 }
3343
3344 int32_t onDefault_Weapons()
3345 {
3346 if(jwin_alert("Confirm Reset","Reset weapon/misc. sprite data?", NULL, NULL, "Yes", "Cancel", 'y', 27,get_zc_font(font_lfont)) == 1)
3347 {
3348 saved=false;
3349 reset_wpns(true, &header);
3350 }
3351
3352 return D_O_K;
3353 }
3354
3355 int32_t onDefault_Guys()
3356 {
3357 if(jwin_alert("Confirm Reset","Reset all enemy/NPC data?", NULL, NULL, "Yes", "Cancel", 'y', 27,get_zc_font(font_lfont)) == 1)
3358 {
3359 saved=false;
3360 reset_guys();
3361 }
3362
3363 return D_O_K;
3364 }
3365
3366
3367 int32_t onDefault_Tiles()
3368 {
3369 if(jwin_alert("Confirm Reset","Reset all tiles?", NULL, NULL, "Yes", "Cancel", 'y', 27,get_zc_font(font_lfont)) == 1)
3370 {
3371 saved=false;
3372
3373 if(!init_tiles(true, &header))
3374 {
3375 jwin_alert("Error","Tile reset failed.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
3376 }
3377
3378 refresh(rALL);
3379 }
3380
3381 return D_O_K;
3382 }
3383
3384 void change_sfx(SAMPLE *sfx1, SAMPLE *sfx2);
3385
3386 int32_t onDefault_SFX()
3387 {
3388 if(jwin_alert("Confirm Reset","Reset all sound effects?", NULL, NULL, "Yes", "Cancel", 'y', 27,get_zc_font(font_lfont)) == 1)
3389 {
3390 saved=false;
3391 SAMPLE *temp_sample;
3392
3393 for(int32_t i=1; i<WAV_COUNT; i++)
3394 {
3395 temp_sample = (SAMPLE *)sfxdata[zc_min(i,Z35)].dat;
3396 change_sfx(&customsfxdata[i], temp_sample);
3397 sprintf(sfx_string[i],"s%03d",i);
3398
3399 if(i<Z35)
3400 strcpy(sfx_string[i], old_sfx_string[i-1]);
3401 set_bit(customsfxflag, i<Z35?1:0, i-1);
3402 }
3403 }
3404
3405 return D_O_K;
3406 }
3407
3408
3409 int32_t onDefault_MapStyles()
3410 {
3411 if(jwin_alert("Confirm Reset","Reset all map styles?", NULL, NULL, "Yes", "Cancel", 'y', 27,get_zc_font(font_lfont)) == 1)
3412 {
3413 saved=false;
3414 reset_mapstyles(true, &QMisc);
3415 }
3416
3417 return D_O_K;
3418 }
3419
3420 int onScrollScreen(int dir, bool warp)
3421 {
3422 Map.scroll(dir,warp);
3423 return D_O_K;
3424 }
3425
3426 int32_t onComboColLeft()
3427 {
3428 if(draw_mode==dm_cpool||draw_mode==dm_auto)
3429 ;
3430 else if((First[current_combolist]>0)&&(draw_mode!=dm_alias))
3431 {
3432 First[current_combolist]-=1;
3433 clear_tooltip();
3434 refresh(rCOMBOS);
3435 }
3436 else if((combo_alistpos[current_comboalist]>0)&&(draw_mode==dm_alias))
3437 {
3438 combo_alistpos[current_comboalist]-=1;
3439 clear_tooltip();
3440 refresh(rCOMBOS);
3441 }
3442
3443 clear_keybuf();
3444 return D_O_K;
3445 }
3446
3447 int32_t onComboColRight()
3448 {
3449 auto& sqr = (draw_mode == dm_alias ? comboaliaslist[current_comboalist] : combolist[current_combolist]);
3450 if(draw_mode==dm_cpool||draw_mode==dm_auto)
3451 ;
3452 else if((First[current_combolist]<(MAXCOMBOS-(sqr.w*sqr.h)))&&(draw_mode!=dm_alias))
3453 {
3454 First[current_combolist]+=1;
3455 clear_tooltip();
3456 refresh(rCOMBOS);
3457 }
3458 else if((combo_alistpos[current_comboalist]<(MAXCOMBOALIASES-(sqr.w*sqr.h)))&&(draw_mode==dm_alias))
3459 {
3460 combo_alistpos[current_comboalist]+=1;
3461 clear_tooltip();
3462 refresh(rCOMBOS);
3463 }
3464
3465 clear_keybuf();
3466 return D_O_K;
3467 }
3468
3469 int32_t onComboColUp()
3470 {
3471 auto& sqr = (draw_mode == dm_alias ? comboaliaslist[current_comboalist] : combolist[current_combolist]);
3472 if(draw_mode==dm_cpool||draw_mode==dm_auto)
3473 ;
3474 else if((First[current_combolist]>0)&&(draw_mode!=dm_alias))
3475 {
3476 First[current_combolist]-=zc_min(First[current_combolist],sqr.w);
3477 clear_tooltip();
3478
3479 refresh(rCOMBOS);
3480 }
3481 else if((combo_alistpos[current_comboalist]>0)&&(draw_mode==dm_alias))
3482 {
3483 combo_alistpos[current_comboalist]-=zc_min(combo_alistpos[current_comboalist],sqr.w);
3484 clear_tooltip();
3485 refresh(rCOMBOS);
3486 }
3487
3488 clear_keybuf();
3489 return D_O_K;
3490 }
3491
3492 int32_t onComboColDown()
3493 {
3494 auto& sqr = (draw_mode == dm_alias ? comboaliaslist[current_comboalist] : combolist[current_combolist]);
3495
3496 if(draw_mode==dm_cpool||draw_mode==dm_auto)
3497 ;
3498 else if((First[current_combolist]<(MAXCOMBOS-(sqr.w*sqr.h)))&&(draw_mode!=dm_alias))
3499 {
3500 First[current_combolist]+=zc_min((MAXCOMBOS-sqr.w)-First[current_combolist],sqr.w);
3501 clear_tooltip();
3502 refresh(rCOMBOS);
3503 }
3504 else if((combo_alistpos[current_comboalist]<(MAXCOMBOALIASES-(comboaliaslist[0].w*comboaliaslist[0].h)))&&(draw_mode==dm_alias))
3505 {
3506 combo_alistpos[current_comboalist]+=zc_min((MAXCOMBOALIASES-sqr.w)-combo_alistpos[current_comboalist],sqr.w);
3507 clear_tooltip();
3508 refresh(rCOMBOS);
3509 }
3510
3511 clear_keybuf();
3512 return D_O_K;
3513 }
3514
3515 void scrollup(int j)
3516 {
3517 switch(draw_mode)
3518 {
3519 case dm_alias:
3520 {
3521 auto& sqr = comboaliaslist[j];
3522 if(combo_alistpos[j]>0)
3523 {
3524 if(CHECK_CTRL_CMD)
3525 {
3526 combo_alistpos[j]=0;
3527 clear_tooltip();
3528 }
3529 else
3530 {
3531 combo_alistpos[j]-=zc_min(combo_alistpos[j],(sqr.w*sqr.h));
3532 clear_tooltip();
3533 }
3534
3535 refresh(rCOMBOS);
3536 }
3537 break;
3538 }
3539 case dm_cpool:
3540 {
3541 auto& sqr = comboaliaslist[j];
3542 if(combo_pool_listpos[j]>0)
3543 {
3544 if(CHECK_CTRL_CMD)
3545 {
3546 combo_pool_listpos[j]=0;
3547 clear_tooltip();
3548 }
3549 else
3550 {
3551 combo_pool_listpos[j]-=zc_min(combo_pool_listpos[j],(sqr.w*sqr.h));
3552 clear_tooltip();
3553 }
3554
3555 refresh(rCOMBOS);
3556 }
3557 break;
3558 }
3559 case dm_auto:
3560 {
3561 auto& sqr = comboaliaslist[j];
3562 if (combo_auto_listpos[j] > 0)
3563 {
3564 if (CHECK_CTRL_CMD)
3565 {
3566 combo_auto_listpos[j] = 0;
3567 clear_tooltip();
3568 }
3569 else
3570 {
3571 combo_auto_listpos[j] -= zc_min(combo_auto_listpos[j], (sqr.w * sqr.h));
3572 clear_tooltip();
3573 }
3574
3575 refresh(rCOMBOS);
3576 }
3577 break;
3578 }
3579 default:
3580 {
3581 auto& sqr = combolist[j];
3582 if(First[j]>0)
3583 {
3584 if(CHECK_CTRL_CMD)
3585 {
3586 First[j]-=zc_min(First[j],256);
3587 clear_tooltip();
3588 }
3589 else
3590 {
3591 First[j]-=zc_min(First[j],(sqr.w*sqr.h));
3592 clear_tooltip();
3593 }
3594
3595 refresh(rCOMBOS);
3596 }
3597 break;
3598 }
3599 }
3600 }
3601 void scrolldown(int j)
3602 {
3603 switch(draw_mode)
3604 {
3605 case dm_alias:
3606 {
3607 auto& sqr = comboaliaslist[j];
3608 if(combo_alistpos[j]<(MAXCOMBOALIASES-(sqr.w*sqr.h)))
3609 {
3610 if(CHECK_CTRL_CMD)
3611 {
3612 combo_alistpos[j]=MAXCOMBOALIASES-(sqr.w*sqr.h);
3613 clear_tooltip();
3614 }
3615 else
3616 {
3617 combo_alistpos[j]=zc_min((MAXCOMBOALIASES-(sqr.w*sqr.h)),combo_alistpos[j]+(sqr.w*sqr.h));
3618 clear_tooltip();
3619 }
3620
3621 refresh(rCOMBOS);
3622 }
3623 break;
3624 }
3625 case dm_cpool:
3626 {
3627 auto& sqr = comboaliaslist[j];
3628 if(combo_pool_listpos[j]<(MAXCOMBOALIASES-(sqr.w*sqr.h)))
3629 {
3630 if(CHECK_CTRL_CMD)
3631 {
3632 combo_pool_listpos[j]=MAXCOMBOALIASES-(sqr.w*sqr.h);
3633 clear_tooltip();
3634 }
3635 else
3636 {
3637 combo_pool_listpos[j]=zc_min((MAXCOMBOALIASES-(sqr.w*sqr.h)),combo_pool_listpos[j]+(sqr.w*sqr.h));
3638 clear_tooltip();
3639 }
3640
3641 refresh(rCOMBOS);
3642 }
3643 break;
3644 }
3645 case dm_auto:
3646 {
3647 auto& sqr = comboaliaslist[j];
3648 if (combo_auto_listpos[j] < (MAXCOMBOALIASES - (sqr.w * sqr.h)))
3649 {
3650 if (CHECK_CTRL_CMD)
3651 {
3652 combo_auto_listpos[j] = MAXCOMBOALIASES - (sqr.w * sqr.h);
3653 clear_tooltip();
3654 }
3655 else
3656 {
3657 combo_auto_listpos[j] = zc_min((MAXCOMBOALIASES - (sqr.w * sqr.h)), combo_pool_listpos[j] + (sqr.w * sqr.h));
3658 clear_tooltip();
3659 }
3660
3661 refresh(rCOMBOS);
3662 }
3663 break;
3664 }
3665 default:
3666 {
3667 auto& sqr = combolist[j];
3668 if(First[j]<(MAXCOMBOS-(sqr.w*sqr.h)))
3669 {
3670 if(CHECK_CTRL_CMD)
3671 {
3672 First[j]=zc_min((MAXCOMBOS-sqr.w*sqr.h),First[j]+256);
3673 clear_tooltip();
3674 }
3675 else
3676 {
3677 First[j]=zc_min((MAXCOMBOS-(sqr.w*sqr.h)),First[j]+(sqr.w*sqr.h));
3678 clear_tooltip();
3679 }
3680
3681 refresh(rCOMBOS);
3682 }
3683 break;
3684 }
3685 }
3686 }
3687
3688 int32_t onPgUp()
3689 {
3690 switch(draw_mode)
3691 {
3692 case dm_alias:
3693 scrollup(current_comboalist);
3694 break;
3695 case dm_cpool:
3696 scrollup(current_cpoollist);
3697 break;
3698 case dm_auto:
3699 scrollup(current_cautolist);
3700 break;
3701 default:
3702 scrollup(current_combolist);
3703 break;
3704 }
3705 return D_O_K;
3706 }
3707
3708 int32_t onPgDn()
3709 {
3710 switch(draw_mode)
3711 {
3712 case dm_alias:
3713 scrolldown(current_comboalist);
3714 break;
3715 case dm_cpool:
3716 scrolldown(current_cpoollist);
3717 break;
3718 case dm_auto:
3719 scrolldown(current_cautolist);
3720 break;
3721 default:
3722 scrolldown(current_combolist);
3723 break;
3724 }
3725 return D_O_K;
3726 }
3727
3728 int32_t onIncreaseCSet()
3729 {
3730 if(draw_mode!=dm_alias)
3731 {
3732 CSet=wrap(CSet+1,0,13);
3733 refresh(rCOMBOS+rMENU+rCOMBO);
3734 }
3735 else
3736 {
3737 alias_cset_mod=wrap(alias_cset_mod+1,0,13);
3738 }
3739 return D_O_K;
3740 }
3741
3742 int32_t onDecreaseCSet()
3743 {
3744 if(draw_mode!=dm_alias)
3745 {
3746 CSet=wrap(CSet-1,0,13);
3747 refresh(rCOMBOS+rMENU+rCOMBO);
3748 }
3749 else
3750 {
3751 alias_cset_mod=wrap(alias_cset_mod-1,0,13);
3752 }
3753 return D_O_K;
3754 }
3755
3756 int32_t onGotoPage()
3757 {
3758 if (draw_mode==dm_alias)
3759 {
3760 static const int PER_PAGE = 260;
3761 if(optional<int> v = call_get_num("Scroll to Alias Page", 0, MAXCOMBOALIASES/PER_PAGE-1, 0))
3762 combo_alistpos[current_comboalist] = *v*PER_PAGE;
3763 }
3764 else if (draw_mode==dm_cpool)
3765 {
3766 static const int PER_PAGE = 260;
3767 if(optional<int> v = call_get_num("Scroll to Combo Pool Page", 0, MAXCOMBOPOOLS/PER_PAGE-1, 0))
3768 combo_pool_listpos[current_cpoollist] = *v*PER_PAGE;
3769 }
3770 else if (draw_mode == dm_auto)
3771 {
3772 static const int PER_PAGE = 260;
3773 if(optional<int> v = call_get_num("Scroll to Auto Combo Page", 0, MAXAUTOCOMBOS/PER_PAGE-1, 0))
3774 combo_auto_listpos[current_cautolist] = *v*PER_PAGE;
3775 }
3776 else
3777 {
3778 static const int PER_PAGE = 256;
3779 if(optional<int> v = call_get_num("Scroll to Combo Page", 0, MAXCOMBOS/PER_PAGE-1, 0))
3780 First[current_combolist] = *v*PER_PAGE;
3781 }
3782
3783 return D_O_K;
3784 }
3785
3786 static char track_number_str_buf[MIDI_TRACK_BUFFER_SIZE] = {0};
3787 const char *tracknumlist(int32_t index, int32_t *list_size)
3788 {
3789 //memset(track_number_str_buf,0,50);
3790 if(index>=0)
3791 {
3792 bound(index,0,255);
3793 std::string name = zcmusic_get_track_name(zcmusic, index);
3794 sprintf(track_number_str_buf,"%02d %s",index+1, name.c_str());
3795 return track_number_str_buf;
3796 }
3797
3798 *list_size=zcmusic_get_tracks(zcmusic);
3799 return NULL;
3800 }
3801
3802 12 static ListData tracknum_list(tracknumlist, &font);
3803
3804 static DIALOG change_track_dlg[] =
3805 {
3806 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
3807 12 { jwin_win_proc, 60-12, 40, 200-16, 72, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Select Track", NULL, NULL },
3808 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
3809 12 { jwin_droplist_proc, 72-12, 60+4, 161, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &tracknum_list, NULL, NULL },
3810 12 { jwin_button_proc, 70, 87, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
3811 12 { jwin_button_proc, 150, 87, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
3812 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
3813 };
3814 // return list_dlg[2].d1;
3815
3816 int32_t changeTrack()
3817 {
3818 restore_mouse();
3819 change_track_dlg[0].dp2=get_zc_font(font_lfont);
3820 change_track_dlg[2].d1=gme_track;
3821
3822 large_dialog(change_track_dlg);
3823
3824 if(do_zqdialog(change_track_dlg,2)==3)
3825 {
3826 gme_track=change_track_dlg[2].d1;
3827 zcmusic_change_track(zcmusic, gme_track);
3828 }
3829
3830 return D_O_K;
3831 }
3832
3833 void set_media_tunes()
3834 {
3835 media_menu.select_uid(MENUID_MEDIA_TUNES, true);
3836 media_menu.select_uid(MENUID_MEDIA_PLAYMUSIC, false);
3837 disable_hotkey(ZQKEY_AMBIENT_MUSIC, false);
3838 disable_hotkey(ZQKEY_PLAY_MUSIC, false);
3839
3840 media_menu.disable_uid(MENUID_MEDIA_CHANGETRACK, true);
3841 disable_hotkey(ZQKEY_CHANGE_TRACK, true);
3842 }
3843
3844 int32_t playMusic()
3845 {
3846 char *ext;
3847 bool ismidi=false;
3848 char allmusic_types[256];
3849 sprintf(allmusic_types, "%s;mid", zcmusic_types);
3850
3851 if(prompt_for_existing_file_compat("Load Music",(char*)allmusic_types,NULL,midipath,false))
3852 {
3853 strcpy(midipath,temppath);
3854
3855 ext=get_extension(midipath);
3856
3857 if(
3858 (stricmp(ext,"ogg")==0)||
3859 (stricmp(ext,"mp3")==0)||
3860 (stricmp(ext,"it")==0)||
3861 (stricmp(ext,"xm")==0)||
3862 (stricmp(ext,"s3m")==0)||
3863 (stricmp(ext,"mod")==0)||
3864 (stricmp(ext,"spc")==0)||
3865 (stricmp(ext,"gym")==0)||
3866 (stricmp(ext,"nsf")==0)||
3867 (stricmp(ext,"gbs")==0)||
3868 (stricmp(ext,"vgm")==0)
3869 )
3870 {
3871 ismidi=false;
3872 }
3873 else if((stricmp(ext,"mid")==0))
3874 {
3875 ismidi=true;
3876 }
3877 else
3878 {
3879 return D_O_K;
3880 }
3881
3882 zc_stop_midi();
3883
3884 if(zcmusic != NULL)
3885 {
3886 zcmusic_stop(zcmusic);
3887 zcmusic_unload_file(zcmusic);
3888 zcmusic = NULL;
3889 zcmixer->newtrack = NULL;
3890 }
3891
3892 if(ismidi)
3893 {
3894 packfile_password("");
3895 if((song=load_midi(midipath))!=NULL)
3896 {
3897 if(zc_play_midi(song,true)==0)
3898 {
3899 media_menu.select_uid(MENUID_MEDIA_TUNES, false);
3900 media_menu.select_uid(MENUID_MEDIA_PLAYMUSIC, true);
3901 disable_hotkey(ZQKEY_AMBIENT_MUSIC, false);
3902 disable_hotkey(ZQKEY_PLAY_MUSIC, false);
3903
3904 media_menu.disable_uid(MENUID_MEDIA_CHANGETRACK, true);
3905 disable_hotkey(ZQKEY_CHANGE_TRACK, true);
3906 }
3907 }
3908 }
3909 else
3910 {
3911 gme_track=0;
3912 zcmusic = (ZCMUSIC*)zcmusic_load_file(midipath);
3913
3914 if(zcmusic!=NULL)
3915 {
3916 media_menu.select_uid(MENUID_MEDIA_TUNES, false);
3917 media_menu.select_uid(MENUID_MEDIA_PLAYMUSIC, true);
3918 disable_hotkey(ZQKEY_AMBIENT_MUSIC, false);
3919 disable_hotkey(ZQKEY_PLAY_MUSIC, false);
3920
3921 bool distrack = zcmusic_get_tracks(zcmusic)<2;
3922 media_menu.disable_uid(MENUID_MEDIA_CHANGETRACK, distrack);
3923 disable_hotkey(ZQKEY_CHANGE_TRACK, distrack);
3924
3925 zcmusic_play(zcmusic, midi_volume);
3926 }
3927 }
3928 }
3929
3930 return D_O_K;
3931 }
3932
3933 int32_t playZCForever()
3934 {
3935 stopMusic();
3936
3937 zcmusic = zcmusic_load_file("assets/zc/ZC_Forever_HD.mp3");
3938 if (zcmusic)
3939 {
3940 zcmusic_play(zcmusic, midi_volume);
3941 set_media_tunes();
3942 }
3943 return D_O_K;
3944 }
3945
3946 // It took awhile to get these values right, so no meddlin'!
3947 int32_t playTune1()
3948 {
3949 return playTune(0);
3950 }
3951 int32_t playTune2()
3952 {
3953 return playTune(81);
3954 }
3955 int32_t playTune3()
3956 {
3957 return playTune(233);
3958 }
3959 int32_t playTune4()
3960 {
3961 return playTune(553);
3962 }
3963 int32_t playTune5()
3964 {
3965 return playTune(814);
3966 }
3967 int32_t playTune6()
3968 {
3969 return playTune(985);
3970 }
3971 int32_t playTune7()
3972 {
3973 return playTune(1153);
3974 }
3975 int32_t playTune8()
3976 {
3977 return playTune(1333);
3978 }
3979 int32_t playTune9()
3980 {
3981 return playTune(1556);
3982 }
3983 int32_t playTune10()
3984 {
3985 return playTune(1801);
3986 }
3987 int32_t playTune11()
3988 {
3989 return playTune(2069);
3990 }
3991 int32_t playTune12()
3992 {
3993 return playTune(2189);
3994 }
3995 int32_t playTune13()
3996 {
3997 return playTune(2569);
3998 }
3999 int32_t playTune14()
4000 {
4001 return playTune(2753);
4002 }
4003 int32_t playTune15()
4004 {
4005 return playTune(2856);
4006 }
4007 int32_t playTune16()
4008 {
4009 return playTune(3042);
4010 }
4011 int32_t playTune17()
4012 {
4013 return playTune(3125);
4014 }
4015 int32_t playTune18()
4016 {
4017 return playTune(3217);
4018 }
4019 int32_t playTune19()
4020 {
4021 return playTune(3296);
4022 }
4023
4024 int32_t playTune(int32_t pos)
4025 {
4026 zc_stop_midi();
4027
4028 if(zcmusic != NULL)
4029 {
4030 zcmusic_stop(zcmusic);
4031 zcmusic_unload_file(zcmusic);
4032 zcmusic = NULL;
4033 zcmixer->newtrack = NULL;
4034 }
4035
4036 if(zc_play_midi(asset_tunes_midi,true)==0)
4037 {
4038 zc_midi_seek(pos);
4039 set_media_tunes();
4040 }
4041
4042 return D_O_K;
4043 }
4044
4045 int32_t stopMusic()
4046 {
4047 zc_stop_midi();
4048
4049 if(zcmusic != NULL)
4050 {
4051 zcmusic_stop(zcmusic);
4052 zcmusic_unload_file(zcmusic);
4053 zcmusic = NULL;
4054 zcmixer->newtrack = NULL;
4055 }
4056
4057 media_menu.select_uid(MENUID_MEDIA_TUNES, false);
4058 media_menu.select_uid(MENUID_MEDIA_PLAYMUSIC, false);
4059 disable_hotkey(ZQKEY_AMBIENT_MUSIC, false);
4060 disable_hotkey(ZQKEY_PLAY_MUSIC, false);
4061
4062 media_menu.disable_uid(MENUID_MEDIA_CHANGETRACK, true);
4063 disable_hotkey(ZQKEY_CHANGE_TRACK, true);
4064 return D_O_K;
4065 }
4066
4067 static int32_t gamemisc1_list[] =
4068 {
4069 5,6,7,8,
4070 9,10,11,12,
4071
4072 37,38,39,40,
4073 41,42,43,44,
4074
4075 71,72,73,74,
4076 75,76,77,78,
4077
4078 -1
4079 };
4080
4081 static int32_t gamemisc2_list[] =
4082 {
4083 13,14,15,16,
4084 17,18,19,20,
4085
4086 45,46,47,48,
4087 49,50,51,52,
4088
4089 79,80,81,82,
4090 83,84,85,86,
4091
4092 -1
4093 };
4094
4095 static int32_t gamemisc3_list[] =
4096 {
4097 21,22,23,24,
4098 25,26,27,28,
4099
4100 53,54,55,56,
4101 57,58,59,60,
4102
4103 87,88,89,90,
4104 91,92,93,94,
4105
4106 -1
4107 };
4108
4109 static int32_t gamemisc4_list[] =
4110 {
4111 29,30,31,32,
4112 33,34,35,36,
4113
4114 61,62,63,64,
4115 65,66,67,68,
4116
4117 95,96,97,98,
4118 99,100,101,102,
4119
4120 -1
4121 };
4122
4123 static TABPANEL gamemisc_tabs[] =
4124 {
4125 // (text)
4126 { (char *)" Misc[0-7] ", D_SELECTED, gamemisc1_list, 0, NULL },
4127 { (char *)" Misc[8-15] ", 0, gamemisc2_list, 0, NULL },
4128 { (char *)" Misc[16-23] ", 0, gamemisc3_list, 0, NULL },
4129 { (char *)" Misc[24-31] ", 0, gamemisc4_list, 0, NULL },
4130 { NULL, 0, NULL, 0, NULL }
4131 };
4132
4133 //to do: Make string boxes larger, and split into two tabs.
4134 static DIALOG gamemiscarray_dlg[] =
4135 {
4136 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
4137
4138 { jwin_win_proc, 0, 10, 310, 224, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Game->Misc[]", NULL, NULL },
4139 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4140 { jwin_tab_proc, 3, 26, 304, 174, vc(14), vc(1), 0, 0, 1, 0, (void *) gamemisc_tabs, NULL, (void *)gamemiscarray_dlg },
4141 { d_dummy_proc, 240, 144, 40, 8, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
4142 { d_dummy_proc, 240, 144, 40, 8, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
4143
4144 //5
4145 { jwin_edit_proc, 8, 42, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4146 { jwin_edit_proc, 8, 42+20, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4147 { jwin_edit_proc, 8, 42+40, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4148 //8
4149 { jwin_edit_proc, 8, 42+60, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4150 { jwin_edit_proc, 8, 42+80, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4151 { jwin_edit_proc, 8, 42+100, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4152 { jwin_edit_proc, 8, 42+120, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4153 { jwin_edit_proc, 8, 42+140, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4154 //13
4155 { jwin_edit_proc, 8, 42, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4156 { jwin_edit_proc, 8, 42+20, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4157 { jwin_edit_proc, 8, 42+40, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4158 { jwin_edit_proc, 8, 42+60, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4159 { jwin_edit_proc, 8, 42+80, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4160 //18
4161 { jwin_edit_proc, 8, 42+100, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4162 { jwin_edit_proc, 8, 42+120, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4163 { jwin_edit_proc, 8, 42+140, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4164 { jwin_edit_proc, 8, 42, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4165 { jwin_edit_proc, 8, 42+20, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4166 //23
4167 { jwin_edit_proc, 8, 42+40, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4168 { jwin_edit_proc, 8, 42+60, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4169 { jwin_edit_proc, 8, 42+80, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4170 { jwin_edit_proc, 8, 42+100, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4171 { jwin_edit_proc, 8, 42+120, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4172 //28
4173 { jwin_edit_proc, 8, 42+140, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4174 { jwin_edit_proc, 8, 42, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4175 { jwin_edit_proc, 8, 42+20, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4176 { jwin_edit_proc, 8, 42+40, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4177 { jwin_edit_proc, 8, 42+60, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4178 //33
4179 { jwin_edit_proc, 8, 42+80, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4180 { jwin_edit_proc, 8, 42+100, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4181 { jwin_edit_proc, 8, 42+120, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4182 { jwin_edit_proc, 8, 42+140, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4183 //37
4184 { jwin_numedit_swap_zsint_proc, 96, 42, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4185 { jwin_numedit_swap_zsint_proc, 96, 42+20, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4186 //39
4187 { jwin_numedit_swap_zsint_proc, 96, 42+40, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4188 { jwin_numedit_swap_zsint_proc, 96, 42+60, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4189 { jwin_numedit_swap_zsint_proc, 96, 42+80, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4190 { jwin_numedit_swap_zsint_proc, 96, 42+100, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4191 { jwin_numedit_swap_zsint_proc, 96, 42+120, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4192 //44
4193 { jwin_numedit_swap_zsint_proc, 96, 42+140, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4194 { jwin_numedit_swap_zsint_proc, 96, 42, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4195 { jwin_numedit_swap_zsint_proc, 96, 42+20, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4196
4197 { jwin_numedit_swap_zsint_proc, 96, 42+40, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4198 { jwin_numedit_swap_zsint_proc, 96, 42+60, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4199 //49
4200 { jwin_numedit_swap_zsint_proc, 96, 42+80, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4201 { jwin_numedit_swap_zsint_proc, 96, 42+100, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4202 { jwin_numedit_swap_zsint_proc, 96, 42+120, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4203 { jwin_numedit_swap_zsint_proc, 96, 42+140, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4204 { jwin_numedit_swap_zsint_proc, 96, 42, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4205 //54
4206 { jwin_numedit_swap_zsint_proc, 96, 42+20, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4207 { jwin_numedit_swap_zsint_proc, 96, 42+40, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4208 { jwin_numedit_swap_zsint_proc, 96, 42+60, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4209 { jwin_numedit_swap_zsint_proc, 96, 42+80, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4210 { jwin_numedit_swap_zsint_proc, 96, 42+100, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4211 //59
4212 { jwin_numedit_swap_zsint_proc, 96, 42+120, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4213 { jwin_numedit_swap_zsint_proc, 96, 42+140, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4214 { jwin_numedit_swap_zsint_proc, 96, 42, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4215 { jwin_numedit_swap_zsint_proc, 96, 42+20, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4216 { jwin_numedit_swap_zsint_proc, 96, 42+40, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4217 //64
4218 { jwin_numedit_swap_zsint_proc, 96, 42+60, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4219 { jwin_numedit_swap_zsint_proc, 96, 42+80, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4220 { jwin_numedit_swap_zsint_proc, 96, 42+100, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4221 { jwin_numedit_swap_zsint_proc, 96, 42+120, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4222 { jwin_numedit_swap_zsint_proc, 96, 42+140, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4223 //69
4224 { jwin_button_proc, 70, 204, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
4225 { jwin_button_proc, 170, 204, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
4226
4227 //71
4228 { jwin_swapbtn_proc, 156, 42, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4229 { jwin_swapbtn_proc, 156, 62, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4230 { jwin_swapbtn_proc, 156, 82, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4231 { jwin_swapbtn_proc, 156, 102, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4232 { jwin_swapbtn_proc, 156, 122, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4233 { jwin_swapbtn_proc, 156, 142, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4234 { jwin_swapbtn_proc, 156, 162, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4235 { jwin_swapbtn_proc, 156, 182, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4236 //79
4237 { jwin_swapbtn_proc, 156, 42, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4238 { jwin_swapbtn_proc, 156, 62, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4239 { jwin_swapbtn_proc, 156, 82, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4240 { jwin_swapbtn_proc, 156, 102, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4241 { jwin_swapbtn_proc, 156, 122, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4242 { jwin_swapbtn_proc, 156, 142, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4243 { jwin_swapbtn_proc, 156, 162, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4244 { jwin_swapbtn_proc, 156, 182, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4245 //87
4246 { jwin_swapbtn_proc, 156, 42, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4247 { jwin_swapbtn_proc, 156, 62, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4248 { jwin_swapbtn_proc, 156, 82, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4249 { jwin_swapbtn_proc, 156, 102, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4250 { jwin_swapbtn_proc, 156, 122, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4251 { jwin_swapbtn_proc, 156, 142, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4252 { jwin_swapbtn_proc, 156, 162, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4253 { jwin_swapbtn_proc, 156, 182, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4254 //95
4255 { jwin_swapbtn_proc, 156, 42, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4256 { jwin_swapbtn_proc, 156, 62, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4257 { jwin_swapbtn_proc, 156, 82, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4258 { jwin_swapbtn_proc, 156, 102, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4259 { jwin_swapbtn_proc, 156, 122, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4260 { jwin_swapbtn_proc, 156, 142, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4261 { jwin_swapbtn_proc, 156, 162, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4262 { jwin_swapbtn_proc, 156, 182, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4263
4264 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
4265 };
4266
4267 // +----------+
4268 // | |
4269 // | View Pic |
4270 // | |
4271 // | |
4272 // | |
4273 // +----------+
4274
4275 BITMAP *pic=NULL;
4276 BITMAP *bmap=NULL;
4277 PALETTE picpal;
4278 PALETTE mappal;
4279 int32_t picx=0,picy=0,mapx=0,mapy=0,pblack,pwhite;
4280
4281 double picscale=1.0,mapscale=1.0;
4282 bool vp_showpal=true, vp_showsize=true, vp_center=true;
4283
4284 //INLINE int32_t pal_sum(RGB p) { return p.r + p.g + p.b; }
4285
4286 void get_bw(RGB *pal,int32_t &black,int32_t &white)
4287 {
4288 black=white=1;
4289
4290 for(int32_t i=1; i<256; i++)
4291 {
4292 if(pal_sum(pal[i])<pal_sum(pal[black]))
4293 black=i;
4294
4295 if(pal_sum(pal[i])>pal_sum(pal[white]))
4296 white=i;
4297 }
4298 }
4299
4300 void draw_bw_mouse(int32_t white, int32_t old_mouse, int32_t new_mouse)
4301 {
4302 blit(mouse_bmp[old_mouse][0],mouse_bmp[new_mouse][0],0,0,0,0,16,16);
4303
4304 for(int32_t y=0; y<16; y++)
4305 {
4306 for(int32_t x=0; x<16; x++)
4307 {
4308 if(getpixel(mouse_bmp[new_mouse][0],x,y)!=0)
4309 {
4310 putpixel(mouse_bmp[new_mouse][0],x,y,white);
4311 }
4312 }
4313 }
4314 }
4315
4316 int32_t load_the_pic(BITMAP **dst, PALETTE dstpal)
4317 {
4318 PALETTE temppal;
4319
4320 for(int32_t i=0; i<256; i++)
4321 {
4322 temppal[i]=dstpal[i];
4323 dstpal[i]=RAMpal[i];
4324 }
4325
4326 // set up the new palette
4327 for(int32_t i=0; i<64; i++)
4328 {
4329 dstpal[i].r = i;
4330 dstpal[i].g = i;
4331 dstpal[i].b = i;
4332 }
4333
4334 zc_set_palette(dstpal);
4335
4336 BITMAP *graypic = create_bitmap_ex(8,screen->w,screen->h);
4337 int32_t _w = screen->w-1;
4338 int32_t _h = screen->h-1;
4339
4340 // gray scale the current frame
4341 for(int32_t y=0; y<_h; y++)
4342 {
4343 for(int32_t x=0; x<_w; x++)
4344 {
4345 int32_t c = screen->line[y][x];
4346 int32_t gray = zc_min((temppal[c].r*42 + temppal[c].g*75 + temppal[c].b*14) >> 7, 63);
4347 graypic->line[y][x] = gray;
4348 }
4349 }
4350
4351 blit(graypic,screen,0,0,0,0,screen->w,screen->h);
4352 destroy_bitmap(graypic);
4353 #ifdef __GNUC__
4354 #pragma GCC diagnostic ignored "-Wformat-overflow"
4355 #endif
4356 char extbuf[2][80];
4357 memset(extbuf[0],0,80);
4358 memset(extbuf[1],0,80);
4359 sprintf(extbuf[0], "View Image (%s", snapshotformat_str[0][1]);
4360 strcpy(extbuf[1], snapshotformat_str[0][1]);
4361
4362 for(int32_t i=1; i<ssfmtMAX; ++i)
4363 {
4364 sprintf(extbuf[0], "%s, %s", extbuf[0], snapshotformat_str[i][1]);
4365 sprintf(extbuf[1], "%s;%s", extbuf[1], snapshotformat_str[i][1]);
4366 }
4367
4368 sprintf(extbuf[0], "%s)", extbuf[0]);
4369 #ifdef __GNUC__
4370 #pragma GCC diagnostic pop
4371 #endif
4372
4373 int32_t gotit = prompt_for_existing_file_compat(extbuf[0],extbuf[1],NULL,imagepath,true);
4374
4375 if(!gotit)
4376 {
4377 zc_set_palette(temppal);
4378 get_palette(dstpal);
4379 return 1;
4380 }
4381
4382 strcpy(imagepath,temppath);
4383
4384 if(*dst)
4385 {
4386 destroy_bitmap(*dst);
4387 }
4388
4389 for(int32_t i=0; i<256; i++)
4390 {
4391 dstpal[i].r = 0;
4392 dstpal[i].g = 0;
4393 dstpal[i].b = 0;
4394 }
4395
4396 *dst = load_bitmap(imagepath,picpal);
4397
4398 if(!*dst)
4399 {
4400 jwin_alert("Error","Error loading image:",imagepath,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
4401 return 2;
4402 }
4403
4404 // get_bw(picpal,pblack,pwhite);
4405 // draw_bw_mouse(pwhite);
4406 // gui_bg_color = pblack;
4407 // gui_fg_color = pwhite;
4408
4409 if(vp_center)
4410 {
4411 picx=picy=0;
4412 }
4413 else
4414 {
4415 picx=(*dst)->w-zq_screen_w;
4416 picy=(*dst)->h-zq_screen_h;
4417 }
4418
4419 return 0;
4420 }
4421 int load_the_pic_new(BITMAP **dst, PALETTE dstpal)
4422 {
4423 #ifdef __GNUC__
4424 #pragma GCC diagnostic ignored "-Wformat-overflow"
4425 #endif
4426 char extbuf[2][80];
4427 memset(extbuf[0],0,80);
4428 memset(extbuf[1],0,80);
4429 sprintf(extbuf[0], "View Image (%s", snapshotformat_str[0][1]);
4430 strcpy(extbuf[1], snapshotformat_str[0][1]);
4431
4432 for(int32_t i=1; i<ssfmtMAX; ++i)
4433 {
4434 sprintf(extbuf[0], "%s, %s", extbuf[0], snapshotformat_str[i][1]);
4435 sprintf(extbuf[1], "%s;%s", extbuf[1], snapshotformat_str[i][1]);
4436 }
4437
4438 sprintf(extbuf[0], "%s)", extbuf[0]);
4439 #ifdef __GNUC__
4440 #pragma GCC diagnostic pop
4441 #endif
4442
4443 int32_t gotit = prompt_for_existing_file_compat(extbuf[0],extbuf[1],NULL,imagepath,true);
4444
4445 if(!gotit)
4446 return 1;
4447
4448 strcpy(imagepath,temppath);
4449
4450 if(*dst)
4451 destroy_bitmap(*dst);
4452
4453 for(int32_t i=0; i<256; i++)
4454 {
4455 dstpal[i].r = 0;
4456 dstpal[i].g = 0;
4457 dstpal[i].b = 0;
4458 }
4459
4460 *dst = load_bitmap(imagepath,dstpal);
4461
4462 if(!*dst)
4463 {
4464 jwin_alert("Error","Error loading image:",imagepath,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
4465 return 2;
4466 }
4467
4468 if(vp_center)
4469 {
4470 picx=picy=0;
4471 }
4472 else
4473 {
4474 picx=(*dst)->w-zq_screen_w;
4475 picy=(*dst)->h-zq_screen_h;
4476 }
4477
4478 return 0;
4479 }
4480
4481 int32_t saveMapAsImage(ALLEGRO_BITMAP* bitmap)
4482 {
4483 char buf[200];
4484 int32_t num=0;
4485
4486 do
4487 {
4488 snprintf(buf, 200, "%szquest_map%05d.%s", get_snap_str(), ++num, snapshotformat_str[SnapshotFormat][1]);
4489 buf[199]='\0';
4490 }
4491 while(num<99999 && exists(buf));
4492
4493 if (!al_save_bitmap(buf, bitmap))
4494 InfoDialog("Error", "Failed to save map image").show();
4495
4496 return D_O_K;
4497 }
4498
4499 int32_t onViewPic()
4500 {
4501 return launchPicViewer(&pic,picpal,&picx,&picy,&picscale,false);
4502 }
4503
4504
4505 class MapViewRTI : public RenderTreeItem
4506 {
4507 public:
4508
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
12 MapViewRTI(): RenderTreeItem("map_view")
4509 12 {
4510 12 }
4511
4512 int bw, bh, sw, sh, flags;
4513
4514 private:
4515 void render(bool bitmap_resized)
4516 {
4517 MapCursor previous_cursor = Map.getCursor();
4518 Map.setViewSize(1);
4519
4520 BITMAP* bmap4_single = create_bitmap_ex(8,256,176);
4521 set_bitmap_create_flags(true);
4522 ALLEGRO_BITMAP* bmap5_single = al_create_bitmap(256,176);
4523 for(int32_t y=0; y<8; y++)
4524 {
4525 for(int32_t x=0; x<16; x++)
4526 {
4527 clear_bitmap(bmap4_single);
4528 Map.setCurrScr(y*16+x);
4529 Map.draw(bmap4_single, 0, 0, flags, -1, y*16+x, -1);
4530 stretch_blit(bmap4_single, bmap4_single, 0, 0, 0, 0, 256, 176, 256, 176);
4531 all_render_a5_bitmap(bmap4_single, bmap5_single);
4532 al_draw_scaled_bitmap(bmap5_single, 0, 0, 256, 176, sw * x, sh * y, sw, sh, 0);
4533 }
4534 }
4535
4536 Map.setCursor(previous_cursor);
4537 destroy_bitmap(bmap4_single);
4538 al_destroy_bitmap(bmap5_single);
4539 }
4540 };
4541 12 static MapViewRTI rti_map_view;
4542
4543 int32_t launchPicViewer(BITMAP **pictoview, PALETTE pal, int32_t *px2, int32_t *py2, double *scale2, bool isviewingmap, bool skipmenu)
4544 {
4545 restore_mouse();
4546 BITMAP *buf;
4547 bool done=false, redraw=true;
4548
4549 popup_zqdialog_start();
4550
4551 // Always call load_the_map() when viewing the map.
4552 if((!*pictoview || isviewingmap) && (isviewingmap ? load_the_map(skipmenu) : load_the_pic(pictoview,pal)))
4553 {
4554 zc_set_palette(RAMpal);
4555 popup_zqdialog_end();
4556 close_the_map();
4557 return D_O_K;
4558 }
4559
4560 get_bw(pal,pblack,pwhite);
4561
4562 int32_t oldfgcolor = gui_fg_color;
4563 int32_t oldbgcolor = gui_bg_color;
4564
4565 buf = create_bitmap_ex(8,zq_screen_w,zq_screen_h);
4566
4567 if(!buf)
4568 {
4569 jwin_alert("Error","Error creating temp bitmap",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
4570 popup_zqdialog_end();
4571 close_the_map();
4572 return D_O_K;
4573 }
4574
4575 static LegacyBitmapRTI viewer_overlay_rti("viewer_overlay");
4576 viewer_overlay_rti.set_size(buf->w, buf->h);
4577 viewer_overlay_rti.a4_bitmap = buf;
4578 viewer_overlay_rti.transparency_index = 15;
4579 get_root_rti()->add_child(&viewer_overlay_rti);
4580
4581 zc_set_palette(pal);
4582
4583 if(isviewingmap)
4584 {
4585 set_center_root_rti(false);
4586
4587 int sw = rti_map_view.width / 16;
4588 int sh = rti_map_view.height / 8;
4589 int screen = Map.getCurrScr();
4590 if (screen >= 0x00 && screen <= 0x7F)
4591 {
4592 auto root_transform = get_root_rti()->get_transform();
4593 int dw = al_get_display_width(all_get_display()) / root_transform.xscale;
4594 int dh = al_get_display_height(all_get_display()) / root_transform.yscale;
4595 mapx = (-(screen % 16) * sw - sw/2 + dw/2);
4596 mapy = (-(screen / 16) * sh - sh/2 + dh/2);
4597 }
4598 }
4599
4600 do
4601 {
4602 int w, h;
4603 if (isviewingmap)
4604 {
4605 w = rti_map_view.width;
4606 h = rti_map_view.height;
4607 }
4608 else
4609 {
4610 w = (*pictoview)->w;
4611 h = (*pictoview)->h;
4612 }
4613
4614 if (isviewingmap)
4615 {
4616 float scale = *scale2;
4617 auto root_transform = get_root_rti()->get_transform();
4618 int dw = al_get_display_width(all_get_display()) / root_transform.xscale;
4619 int dh = al_get_display_height(all_get_display()) / root_transform.yscale;
4620 mapx = std::max(mapx, (int)(-w*scale + dw));
4621 mapy = std::max(mapy, (int)(-h*scale + dh));
4622 mapx = std::min(mapx, 0);
4623 mapy = std::min(mapy, 0);
4624 rti_map_view.set_transform({mapx, mapy, scale, scale});
4625 }
4626
4627 if(redraw)
4628 {
4629 clear_to_color(buf,15);
4630
4631 if (!isviewingmap)
4632 stretch_blit(*pictoview, buf, 0, 0, w, h,
4633 int32_t(zq_screen_w + (*px2 - w) * *scale2) / 2, int32_t(zq_screen_h + (*py2 - h) * *scale2) / 2,
4634 int32_t(w * *scale2), int32_t(h * *scale2));
4635
4636 if(vp_showpal)
4637 for(int32_t i=0; i<256; i++)
4638 rectfill(buf,((i&15)<<2)+zq_screen_w-64,((i>>4)<<2)+zq_screen_h-64,((i&15)<<2)+zq_screen_w-64+3,((i>>4)<<2)+zq_screen_h-64+3,i);
4639
4640 if(vp_showsize)
4641 {
4642 textprintf_ex(buf,font,0,zq_screen_h-8,pwhite,pblack,"%dx%d %.2f%%",w,h,*scale2*100.0);
4643 }
4644
4645 if (!isviewingmap)
4646 blit(buf,screen,0,0,0,0,zq_screen_w,zq_screen_h);
4647 redraw=false;
4648 }
4649
4650 custom_vsync();
4651
4652 int32_t step = 16;
4653
4654 if(*scale2 < 1.0)
4655 step = int32_t(4.0/ *scale2);
4656
4657 if(key[KEY_LSHIFT] || key[KEY_RSHIFT])
4658 step <<= 2;
4659
4660 if(CHECK_CTRL_CMD)
4661 step >>= 1;
4662
4663 if(key[KEY_UP])
4664 {
4665 *py2+=step;
4666 redraw=true;
4667 }
4668
4669 if(key[KEY_DOWN])
4670 {
4671 *py2-=step;
4672 redraw=true;
4673 }
4674
4675 if(key[KEY_LEFT])
4676 {
4677 *px2+=step;
4678 redraw=true;
4679 }
4680
4681 if(key[KEY_RIGHT])
4682 {
4683 *px2-=step;
4684 redraw=true;
4685 }
4686
4687 if(keypressed() && !redraw)
4688 switch(readkey()>>8)
4689 {
4690 case KEY_PGUP:
4691 *scale2*=0.95;
4692
4693 if(*scale2<0.1) *scale2=0.1;
4694
4695 redraw=true;
4696 break;
4697
4698 case KEY_PGDN:
4699 *scale2/=0.95;
4700
4701 if(*scale2>5.0) *scale2=5.0;
4702
4703 redraw=true;
4704 break;
4705
4706 case KEY_HOME:
4707 *scale2/=2.0;
4708
4709 if(*scale2<0.1) *scale2=0.1;
4710
4711 redraw=true;
4712 break;
4713
4714 case KEY_END:
4715 *scale2*=2.0;
4716
4717 if(*scale2>5.0) *scale2=5.0;
4718
4719 redraw=true;
4720 break;
4721
4722 case KEY_TILDE:
4723 *scale2=0.5;
4724 redraw=true;
4725 break;
4726
4727 case KEY_Z:
4728 *px2=w-zq_screen_w;
4729 *py2=h-zq_screen_h;
4730 vp_center=false;
4731 redraw=true;
4732 break;
4733
4734 case KEY_1:
4735 *scale2=1.0;
4736 redraw=true;
4737 break;
4738
4739 case KEY_2:
4740 *scale2=2.0;
4741 redraw=true;
4742 break;
4743
4744 case KEY_3:
4745 *scale2=3.0;
4746 redraw=true;
4747 break;
4748
4749 case KEY_4:
4750 *scale2=4.0;
4751 redraw=true;
4752 break;
4753
4754 case KEY_5:
4755 *scale2=5.0;
4756 redraw=true;
4757 break;
4758
4759 case KEY_C:
4760 *px2=*py2=0;
4761 redraw=vp_center=true;
4762 break;
4763
4764 case KEY_S:
4765 vp_showsize = !vp_showsize;
4766 redraw=true;
4767 break;
4768
4769 case KEY_D:
4770 vp_showpal = !vp_showpal;
4771 redraw=true;
4772 break;
4773
4774 case KEY_P:
4775 if(isviewingmap) break;
4776
4777 case KEY_ESC:
4778 done=true;
4779 break;
4780
4781 case KEY_SPACE:
4782 close_the_map();
4783 // TODO: why is `load_the_map` rendering a black dialog?
4784 if(isviewingmap ? load_the_map(skipmenu) : load_the_pic(pictoview,pal)==2)
4785 {
4786 done=true;
4787 }
4788 else
4789 {
4790 redraw=true;
4791 gui_bg_color = pblack;
4792 gui_fg_color = pwhite;
4793 *scale2=1.0;
4794 zc_set_palette(pal);
4795 }
4796
4797 get_bw(pal,pblack,pwhite);
4798 break;
4799 }
4800 }
4801 while(!done);
4802
4803 destroy_bitmap(buf);
4804 zc_set_palette(RAMpal);
4805 gui_fg_color = oldfgcolor;
4806 gui_bg_color = oldbgcolor;
4807
4808 popup_zqdialog_end();
4809 position_mouse_z(0);
4810 viewer_overlay_rti.remove();
4811 set_center_root_rti(true);
4812 close_the_map();
4813 return D_O_K;
4814 }
4815
4816 static DIALOG loadmap_dlg[] =
4817 {
4818 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
4819 { jwin_win_proc, 0, 0, 225, 143, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "View Map", NULL, NULL },
4820 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4821 { jwin_text_proc, 32, 26, 96, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Resolution", NULL, NULL },
4822 // 3
4823 { jwin_radio_proc, 16, 36, 97, 9, vc(14), vc(1), 0, 0, 0, 0, (void *) "1/4 - 1024x352", NULL, NULL },
4824 { jwin_radio_proc, 16, 46, 97, 9, vc(14), vc(1), 0, 0, 0, 0, (void *) "1/2 - 2048x704", NULL, NULL },
4825 { jwin_radio_proc, 16, 56, 97, 9, vc(14), vc(1), 0, 0, 0, 0, (void *) "Full - 4096x1408", NULL, NULL },
4826 { jwin_text_proc, 144, 26, 97, 9, vc(11), vc(1), 0, 0, 0, 0, (void *) "Options", NULL, NULL },
4827 // 7
4828 { jwin_check_proc, 144, 36, 97, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Solidity", NULL, NULL },
4829 { jwin_check_proc, 144, 46, 97, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Flags", NULL, NULL },
4830 { jwin_check_proc, 144, 56, 97, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Dark", NULL, NULL },
4831 { jwin_check_proc, 144, 66, 97, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Items", NULL, NULL },
4832 // 11
4833 { jwin_button_proc, 42, 110, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
4834 { jwin_button_proc, 122, 110, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
4835 { jwin_check_proc, 16, 88, 97, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Save to Image", NULL, NULL },
4836 // 14
4837 { jwin_radio_proc, 16, 66, 97, 9, vc(14), vc(1), 0, 0, 0, 0, (void*)"2x - 8192x2816", NULL, NULL },
4838 { jwin_radio_proc, 16, 76, 97, 9, vc(14), vc(1), 0, 0, 0, 0, (void*)"4x - 16384x5632", NULL, NULL },
4839 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
4840 };
4841
4842 int32_t load_the_map(bool skipmenu)
4843 {
4844 static int32_t res = 0;
4845 static int32_t flags = cDEBUG;
4846
4847 loadmap_dlg[0].dp2 = get_zc_font(font_lfont);
4848 loadmap_dlg[3].flags = (res==2) ? D_SELECTED : 0;
4849 loadmap_dlg[4].flags = (res==1) ? D_SELECTED : 0;
4850 loadmap_dlg[5].flags = (res==0) ? D_SELECTED : 0;
4851 loadmap_dlg[7].flags = (flags&cWALK) ? D_SELECTED : 0;
4852 loadmap_dlg[8].flags = (flags&cFLAGS) ? D_SELECTED : 0;
4853 loadmap_dlg[9].flags = (flags&cNODARK) ? 0 : D_SELECTED;
4854 loadmap_dlg[10].flags = (flags&cNOITEM) ? 0 : D_SELECTED;
4855 loadmap_dlg[13].flags = 0;
4856 loadmap_dlg[14].flags = (res==3) ? D_SELECTED : 0;
4857 loadmap_dlg[15].flags = (res==4) ? D_SELECTED : 0;
4858
4859 if(!skipmenu)
4860 {
4861 large_dialog(loadmap_dlg);
4862
4863 if (do_zqdialog(loadmap_dlg, 11) != 11)
4864 {
4865 return 1;
4866 }
4867
4868 flags = cDEBUG;
4869
4870 if(loadmap_dlg[3].flags&D_SELECTED) res=2;
4871
4872 if(loadmap_dlg[4].flags&D_SELECTED) res=1;
4873
4874 if(loadmap_dlg[5].flags&D_SELECTED) res=0;
4875
4876 if(loadmap_dlg[7].flags&D_SELECTED) flags|=cWALK;
4877
4878 if(loadmap_dlg[8].flags&D_SELECTED) flags|=cFLAGS;
4879
4880 if(!(loadmap_dlg[9].flags&D_SELECTED)) flags|=cNODARK;
4881
4882 if(!(loadmap_dlg[10].flags&D_SELECTED)) flags|=cNOITEM;
4883
4884 if(loadmap_dlg[14].flags&D_SELECTED) res=3;
4885
4886 if(loadmap_dlg[15].flags&D_SELECTED) res=4;
4887 }
4888
4889 int32_t bw = (256*16)>>res;
4890 int32_t bh = (176*8)>>res;
4891 int32_t sw = 256>>res;
4892 int32_t sh = 176>>res;
4893 if(res>2)
4894 {
4895 bw = (256*16)<<(res-2);
4896 bh = (176*8)<<(res-2);
4897 sw = 256<<(res-2);
4898 sh = 176<<(res-2);
4899 }
4900
4901 rti_map_view.flags = flags;
4902 rti_map_view.bw = bw;
4903 rti_map_view.bh = bh;
4904 rti_map_view.sw = sw;
4905 rti_map_view.sh = sh;
4906 rti_map_view.set_size(bw, bh);
4907 rti_map_view.dirty = true;
4908 get_root_rti()->add_child(&rti_map_view);
4909 render_zq();
4910
4911 vp_showpal = false;
4912 get_bw(picpal,pblack,pwhite);
4913 mapx = mapy = 0;
4914 mapscale = 1;
4915 imagepath[0] = 0;
4916
4917 if(loadmap_dlg[13].flags & D_SELECTED) saveMapAsImage(rti_map_view.bitmap);
4918
4919 memcpy(mappal,RAMpal,sizeof(RAMpal));
4920
4921 return 0;
4922 }
4923
4924 void close_the_map()
4925 {
4926 rti_map_view.remove();
4927 }
4928
4929 int32_t onViewMap()
4930 {
4931 return onViewMapEx(false);
4932 }
4933 int32_t onViewMapEx(bool skipmenu)
4934 {
4935 int32_t temp_aligns=ShowMisalignments;
4936 ShowMisalignments=0;
4937 //if(load_the_map()==0)
4938 //{
4939 launchPicViewer(&bmap,mappal,&mapx, &mapy, &mapscale,true,skipmenu);
4940 //}
4941 ShowMisalignments=temp_aligns;
4942 return D_O_K;
4943 }
4944
4945 static const char *mazedirstr[4] = {"North","South","West","East"};
4946 char _pathstr[40]="North,North,North,North";
4947
4948 char *pathstr(byte path[])
4949 {
4950 sprintf(_pathstr,"%s,%s,%s,%s",mazedirstr[path[0]],mazedirstr[path[1]],
4951 mazedirstr[path[2]],mazedirstr[path[3]]);
4952 return _pathstr;
4953 }
4954
4955 char _ticksstr[32]="99.99 seconds";
4956
4957 char *ticksstr(int32_t tics)
4958 {
4959 int32_t mins=tics/(60*60);
4960 tics=tics-(mins*60*60);
4961 int32_t secs=tics/60;
4962 tics=tics-(secs*60);
4963 tics=tics*100/60;
4964
4965 if(mins>0)
4966 {
4967 sprintf(_ticksstr,"%d:%02d.%02d",mins, secs, tics);
4968 }
4969 else
4970 {
4971 sprintf(_ticksstr,"%d.%02d seconds",secs, tics);
4972 }
4973
4974 return _ticksstr;
4975 }
4976
4977 ZC_FORMAT_PRINTF(7, 8)
4978 void textprintf_disabled(BITMAP *bmp, AL_CONST FONT *f, int32_t x, int32_t y, int32_t color_hl, int32_t color_sh, AL_CONST char *format, ...)
4979 {
4980 char buf[512];
4981 va_list ap;
4982 ASSERT(bmp);
4983 ASSERT(f);
4984 ASSERT(format);
4985
4986 va_start(ap, format);
4987 uvszprintf(buf, sizeof(buf), format, ap);
4988 va_end(ap);
4989
4990
4991 textout_ex(bmp, f, buf, x+1, y+1, color_hl, -1);
4992
4993 textout_ex(bmp, f, buf, x, y, color_sh, -1);
4994 }
4995
4996 ZC_FORMAT_PRINTF(7, 8)
4997 void textprintf_centre_disabled(BITMAP *bmp, AL_CONST FONT *f, int32_t x, int32_t y, int32_t color_hl, int32_t color_sh, AL_CONST char *format, ...)
4998 {
4999 char buf[512];
5000 va_list ap;
5001 ASSERT(bmp);
5002 ASSERT(f);
5003 ASSERT(format);
5004
5005 va_start(ap, format);
5006 uvszprintf(buf, sizeof(buf), format, ap);
5007 va_end(ap);
5008
5009 textout_centre_ex(bmp, f, buf, x+1, y+1, color_hl, -1);
5010 textout_centre_ex(bmp, f, buf, x, y, color_sh, -1);
5011 }
5012
5013 void draw_sqr_frame(size_and_pos const& sqr)
5014 {
5015 jwin_draw_frame(menu1,sqr.x,sqr.y,sqr.tw(),sqr.th(),FR_DEEP);
5016 }
5017 void draw_sqr_icon(size_and_pos const& sqr, BITMAP* icon)
5018 {
5019 stretch_blit(icon, menu1, 0, 0, 16, 16, sqr.x+2, sqr.y+2, sqr.tw()-4, sqr.th()-4);
5020 }
5021 void draw_sqr_nums(size_and_pos const& sqr, FONT* f, bool center, int num)
5022 {
5023 if(center)
5024 textprintf_centre_ex(menu1,f,sqr.x+txtoffs_single.x,sqr.y+txtoffs_single.y,jwin_pal[jcBOXFG],-1,"%d",num);
5025 else
5026 textprintf_ex(menu1,f,sqr.x+txtoffs_single.x,sqr.y+txtoffs_single.y,jwin_pal[jcBOXFG],-1,"%d",num);
5027 }
5028 void draw_sqr_nums(size_and_pos const& sqr, FONT* f, bool center, int num1, int num2)
5029 {
5030 if(center)
5031 {
5032 textprintf_centre_ex(menu1,f,sqr.x+txtoffs_double_1.x,sqr.y+txtoffs_double_1.y,jwin_pal[jcBOXFG],-1,"%d",num1);
5033 textprintf_centre_ex(menu1,f,sqr.x+txtoffs_double_2.x,sqr.y+txtoffs_double_2.y,jwin_pal[jcBOXFG],-1,"%d",num2);
5034 }
5035 else
5036 {
5037 textprintf_ex(menu1,f,sqr.x+txtoffs_double_1.x,sqr.y+txtoffs_double_1.y,jwin_pal[jcBOXFG],-1,"%d",num1);
5038 textprintf_ex(menu1,f,sqr.x+txtoffs_double_2.x,sqr.y+txtoffs_double_2.y,jwin_pal[jcBOXFG],-1,"%d",num2);
5039 }
5040 }
5041 void draw_sqr_btn(size_and_pos const& sqr, const char* txt, int flags, FONT* f = nullptr)
5042 {
5043 if(sqr.x < 0) return;
5044 FONT* tfont = font;
5045 if(f)
5046 font = f;
5047 draw_text_button(menu1, sqr.x, sqr.y, sqr.tw(), sqr.th(), txt, 0, 0, flags, true);
5048 font = tfont;
5049 }
5050 void draw_sqr_btn(size_and_pos const& sqr, int icon, int flags, FONT* f = nullptr)
5051 {
5052 if(sqr.x < 0) return;
5053 FONT* tfont = font;
5054 if(f)
5055 font = f;
5056 draw_icon_button(menu1, sqr.x, sqr.y, sqr.tw(), sqr.th(), icon, 0, 0, flags, true);
5057 font = tfont;
5058 }
5059
5060 void drawpanel()
5061 {
5062 mapscr *scr=Map.CurrScr();
5063 int32_t NextCombo = combobuf[Combo].nextcombo;
5064 int32_t NextCSet = combobuf[Combo].nextcset;
5065 if(combobuf[Combo].animflags & AF_CYCLEUNDERCOMBO)
5066 {
5067 NextCombo = scr->undercombo;
5068 NextCSet = scr->undercset;
5069 }
5070 if(combobuf[Combo].animflags & AF_CYCLENOCSET)
5071 NextCSet = CSet;
5072
5073 FONT* tfont = font;
5074 if(prv_mode)
5075 {
5076 jwin_draw_frame(menu1,0,preview_panel.y,preview_panel.x+preview_panel.w, preview_panel.h, FR_WIN);
5077 rectfill(menu1,preview_panel.x,preview_panel.y+2,preview_panel.x+preview_panel.w-3,preview_panel.y+preview_panel.h-3,jwin_pal[jcBOX]);
5078 }
5079 else
5080 {
5081 auto& sqr = main_panel;
5082 rectfill(menu1,sqr.x,sqr.y,sqr.x+sqr.w-1,sqr.y+sqr.h-1, jwin_pal[jcBOX]);
5083 refresh(rSCRMAP);
5084 jwin_draw_frame(menu1,sqr.x,sqr.y,sqr.w,sqr.h, FR_WIN);
5085
5086 font = get_custom_font(CFONT_GUI);
5087 draw_sqr_btn(squarepanel_swap_btn, "SWP", 0);
5088 if(compact_square_panels)
5089 {
5090 textprintf_centre_ex(menu1,font,squarepanel_up_btn.cx(),squarepanel_up_btn.y-text_height(font)-2,jwin_pal[jcBOXFG],-1,"%d",compact_active_panel);
5091 draw_sqr_btn(squarepanel_up_btn, BTNICON_ARROW_UP, 0);
5092 draw_sqr_btn(squarepanel_down_btn, BTNICON_ARROW_DOWN, 0);
5093 }
5094 font = tfont;
5095
5096 FONT* sqr_text_font = (is_compact && compact_square_panels) ? get_custom_font(CFONT_GUI) : font;
5097 //Item:
5098 if(itemsqr_pos.x > -1)
5099 {
5100 draw_sqr_frame(itemsqr_pos);
5101 if(scr->hasitem)
5102 {
5103 rectfill(menu1,itemsqr_pos.x+2,itemsqr_pos.y+2,itemsqr_pos.x+itemsqr_pos.tw()-3,itemsqr_pos.y+itemsqr_pos.th()-3,0);
5104 overtile16_scale(menu1, itemsbuf[scr->item].tile,itemsqr_pos.x+2,itemsqr_pos.y+2,itemsbuf[scr->item].csets&15,0,itemsqr_pos.tw()-4,itemsqr_pos.th()-4);
5105 }
5106 else draw_sqr_icon(itemsqr_pos, icon_bmp[0][coord_frame]);
5107 draw_sqr_nums(itemsqr_pos, sqr_text_font, panel_align == 1, scr->itemx, scr->itemy);
5108 }
5109 //Flag:
5110 if(flagsqr_pos.x > -1)
5111 {
5112 draw_sqr_frame(flagsqr_pos);
5113 draw_sqr_icon(flagsqr_pos,flag_bmp[Flag%16][coord_frame]);
5114 draw_sqr_nums(flagsqr_pos, sqr_text_font, panel_align == 1, Flag);
5115 }
5116
5117 //Stairs:
5118 if(stairsqr_pos.x > -1)
5119 {
5120 draw_sqr_frame(stairsqr_pos);
5121 draw_sqr_icon(stairsqr_pos,icon_bmp[1][coord_frame]);
5122 draw_sqr_nums(stairsqr_pos, sqr_text_font, panel_align == 1, scr->stairx, scr->stairy);
5123 }
5124
5125 //Green arrival square:
5126 bool disabled_arrival = get_qr(qr_NOARRIVALPOINT);
5127 if(warparrival_pos.x > -1)
5128 {
5129 draw_sqr_frame(warparrival_pos);
5130 BITMAP* icon = icon_bmp[2][coord_frame];
5131 if(disabled_arrival)
5132 {
5133 icon = create_bitmap_ex(8,16,16);
5134 blit(icon_bmp[2][0], icon, 0, 0, 0, 0, 16, 16);
5135 replColor(icon, 0xE7, 0xEA, 0xEA, false);
5136 replColor(icon, 0xE8, 0xE2, 0xE2, false);
5137 }
5138
5139 draw_sqr_icon(warparrival_pos, icon);
5140 draw_sqr_nums(warparrival_pos, sqr_text_font, panel_align == 1, scr->warparrivalx, scr->warparrivaly);
5141
5142 if(disabled_arrival)
5143 destroy_bitmap(icon);
5144 }
5145
5146 //Blue return squares:
5147 for(int32_t i=0; i<4; i++)
5148 {
5149 if(warpret_pos[i].x < 0) continue;
5150 draw_sqr_frame(warpret_pos[i]);
5151 draw_sqr_icon(warpret_pos[i], icon_bmp[ICON_BMP_RETURN_A+i][coord_frame]);
5152 draw_sqr_nums(warpret_pos[i], sqr_text_font, panel_align == 1, scr->warpreturnx[i], scr->warpreturny[i]);
5153 }
5154
5155 // Enemies
5156 auto& ep = enemy_prev_pos;
5157 if(ep.x > -1)
5158 {
5159 if(ep.fw > -1)
5160 {
5161 rectfill(menu1, ep.x, ep.y, ep.x+ep.tw()-1,ep.y+ep.th()-1,vc(0));
5162 rectfill(menu1, ep.x+ep.fw, ep.y+ep.fh, ep.x+ep.tw()-1, ep.y+ep.th()-1, jwin_pal[jcBOX]);
5163 jwin_draw_frag_frame(menu1, ep.x, ep.y, ep.tw(), ep.th(), ep.fw, ep.fh, FR_DEEP);
5164 }
5165 else
5166 {
5167 rectfill(menu1, ep.x, ep.y, ep.x+ep.tw()-1,ep.y+ep.th()-1,vc(0));
5168 draw_sqr_frame(ep);
5169 }
5170 for(int32_t i=0; i< 10 && Map.CurrScr()->enemy[i]!=0; i++)
5171 {
5172 int32_t id = Map.CurrScr()->enemy[i];
5173 int32_t tile = get_qr(qr_NEWENEMYTILES) ? guysbuf[id].e_tile : guysbuf[id].tile;
5174 int32_t cset = guysbuf[id].cset;
5175 auto& sqr = ep.subsquare(i);
5176 if(tile)
5177 overtile16_scale(menu1, tile+efrontfacingtile(id),sqr.x,sqr.y,cset,0,sqr.tw(),sqr.th());
5178 }
5179 }
5180 }
5181 font = tfont;
5182 }
5183
5184 void show_screen_error(const char *str, int32_t i, int32_t c)
5185 {
5186 rectfill(menu1, screrrorpos.x-text_length(get_zc_font(font_lfont_l),str),screrrorpos.y-(i*16),screrrorpos.x,screrrorpos.y-((i-1)*16)-4,vc(0));
5187 textout_shadowed_ex(menu1,get_zc_font(font_lfont_l), str,screrrorpos.x-text_length(get_zc_font(font_lfont_l),str),screrrorpos.y-(i*16),c,vc(0),-1);
5188 }
5189
5190 void tile_warp_notification(int32_t which, char *buf)
5191 {
5192 char letter = 'A'+which;
5193
5194 switch(Map.CurrScr()->tilewarptype[which])
5195 {
5196 case wtCAVE:
5197 sprintf(buf,"Tile Warp %c: Cave/Item Cellar",letter);
5198 break;
5199
5200 default:
5201 {
5202 char buf2[30];
5203
5204 if(strlen(DMaps[Map.CurrScr()->tilewarpdmap[which]].name)==0)
5205 {
5206 sprintf(buf2,"%d",Map.CurrScr()->tilewarpdmap[which]);
5207 }
5208 else
5209 sprintf(buf2,"%d-%s",Map.CurrScr()->tilewarpdmap[which],DMaps[Map.CurrScr()->tilewarpdmap[which]].name);
5210
5211 sprintf(buf,"Tile Warp %c: %s, %02X", letter, buf2, Map.CurrScr()->tilewarpscr[which]);
5212 break;
5213 }
5214
5215 case wtNOWARP:
5216 sprintf(buf,"Tile Warp %c: Cancel Warp", letter);
5217 break;
5218 }
5219 }
5220
5221 void side_warp_notification(int32_t which, int32_t dir, char *buf)
5222 {
5223 char letter = 'A'+which;
5224 char buf3[16];
5225
5226 if(dir==0 && Map.CurrScr()->timedwarptics)
5227 sprintf(buf3,"%s, Timed",mazedirstr[dir]);
5228 else if(dir==4)
5229 sprintf(buf3,"Timed");
5230 else
5231 strcpy(buf3, mazedirstr[dir]);
5232
5233 switch(Map.CurrScr()->sidewarptype[which])
5234 {
5235 case wtCAVE:
5236 sprintf(buf,"Side Warp %c (%s): Cave/Item Cellar",letter, buf3);
5237 break;
5238
5239 default:
5240 {
5241 // Destination DMap name
5242 if(strlen(DMaps[Map.CurrScr()->sidewarpdmap[which]].name)==0)
5243 {
5244 sprintf(buf,"Side Warp %c (%s): %d, %02X", letter, buf3, Map.CurrScr()->sidewarpdmap[which], Map.CurrScr()->sidewarpscr[which]);
5245 }
5246 else
5247 sprintf(buf,"Side Warp %c (%s): %d-%s, %02X", letter, buf3, Map.CurrScr()->sidewarpdmap[which],DMaps[Map.CurrScr()->sidewarpdmap[which]].name, Map.CurrScr()->sidewarpscr[which]);
5248
5249 break;
5250 }
5251
5252 case wtNOWARP:
5253 sprintf(buf,"Side Warp %c (%s): Cancel Warp", letter, buf3);
5254 break;
5255 }
5256 }
5257
5258 static bool arrowcursor = true; // Used by combo aliases and Combo Brush cursors. -L
5259
5260 void xout(BITMAP* dest, int x, int y, int x2, int y2, int c, int bgc = -1)
5261 {
5262 //BG Fill
5263 if(bgc > -1)
5264 rectfill(dest, x, y, x2, y2, bgc);
5265 ++x; ++y; --x2; --y2;
5266 //Border
5267 safe_rect(dest, x, y, x2, y2, c);
5268 //line(dest, x, y, x2, y, c);
5269 //line(dest, x, y, x, y2, c);
5270 //X
5271 line(dest, x, y, x2, y2, c);
5272 line(dest, x, y2, x2, y, c);
5273 }
5274
5275 void put_autocombo_engravings(BITMAP* dest, combo_auto const& ca, bool selected, int32_t x, int32_t y, int32_t scale)
5276 {
5277 if (!ca.valid())
5278 {
5279 if (ca.getDisplay() > 0)
5280 put_engraving(dest, x, y, 15, scale);
5281 }
5282 else
5283 {
5284 if (ca.getType() == AUTOCOMBO_Z4 || ca.getType() == AUTOCOMBO_DOR)
5285 {
5286 byte hei = vbound(ca.getArg() + 1, 1, 9);
5287 if (selected)
5288 hei = vbound(cauto_height, 1, 9);
5289 put_engraving(dest, x, y, 15 - hei, scale);
5290 }
5291 }
5292 }
5293
5294 void draw_screenunit_map_screen(VisibleScreen visible_screen)
5295 {
5296 int num_screens_to_draw = Map.getViewSize();
5297 int screen = visible_screen.screen;
5298 int xoff = visible_screen.xoff;
5299 int yoff = visible_screen.yoff;
5300
5301 mapscr* scr = visible_screen.scr;
5302 if (!layers_valid(scr))
5303 fix_layers(scr, true);
5304
5305 clear_to_color(mapscreenbmp, jwin_pal[jcBOX]);
5306 if (LayerDitherBG > -1)
5307 {
5308 if (LayerDitherSz > 0)
5309 ditherblit(mapscreenbmp, nullptr, vc(LayerDitherBG), dithChecker, LayerDitherSz);
5310 else
5311 clear_to_color(mapscreenbmp, vc(LayerDitherBG));
5312 }
5313
5314 int view_scr_x = Map.getViewScr() % 16;
5315 int view_scr_y = Map.getViewScr() / 16;
5316 int scr_x = screen % 16;
5317 int scr_y = screen / 16;
5318 int edge_xoff = 0, edge_yoff = 0;
5319 if(showedges)
5320 {
5321 if (scr_x == view_scr_x)
5322 edge_xoff = 16;
5323 else
5324 xoff -= 16;
5325
5326 if (scr_y == view_scr_y)
5327 edge_yoff = 16;
5328 else
5329 yoff -= 16;
5330 }
5331
5332 combotile_add_x = mapscreen_x + xoff;
5333 combotile_add_y = mapscreen_y + yoff;
5334 combotile_mul_x = mapscreen_single_scale;
5335 combotile_mul_y = mapscreen_single_scale;
5336 Map.draw(mapscreenbmp, scr_x == view_scr_x && showedges ? 16 : 0, scr_y == view_scr_y && showedges ? 16 : 0, Flags, Map.getCurrMap(), screen, ActiveLayerHighlight ? CurrentLayer : -1);
5337 combotile_add_x = 0;
5338 combotile_add_y = 0;
5339 combotile_mul_x = 1;
5340 combotile_mul_y = 1;
5341
5342 // TODO: should be better to move this out of draw_screenunit_map_screen.
5343 if (showedges && screen < 128)
5344 {
5345 bool peek_above = scr_y == view_scr_y;
5346 bool peek_below = scr_y == view_scr_y + num_screens_to_draw - 1;
5347 bool peek_left = scr_x == view_scr_x;
5348 bool peek_right = scr_x == view_scr_x + num_screens_to_draw - 1;
5349
5350 int right_col = 272 - (num_screens_to_draw > 1 ? 16 : 0);
5351 int bottom_row = 192 - (num_screens_to_draw > 1 ? 16 : 0);
5352
5353 //not the first row of screens
5354 if (peek_above)
5355 {
5356 if(screen>15 && !NoScreenPreview)
5357 {
5358 Map.drawrow(mapscreenbmp, edge_xoff, 0, Flags, 160, -1, screen-16);
5359 }
5360 else
5361 {
5362 Map.drawstaticrow(mapscreenbmp, edge_xoff, 0);
5363 }
5364 }
5365
5366 //not the last row of screens
5367 if (peek_below)
5368 {
5369 if(screen + 16 < 0x80 && !NoScreenPreview)
5370 {
5371 Map.drawrow(mapscreenbmp, edge_xoff, bottom_row, Flags, 0, -1, screen+16);
5372 }
5373 else
5374 {
5375 Map.drawstaticrow(mapscreenbmp, edge_xoff, bottom_row);
5376 }
5377 }
5378
5379 //not the first column of screens
5380 if (peek_left)
5381 {
5382 if(screen&0x0F && !NoScreenPreview)
5383 {
5384 Map.drawcolumn(mapscreenbmp, 0, edge_yoff, Flags, 15, -1, screen-1);
5385 }
5386 else
5387 {
5388 Map.drawstaticcolumn(mapscreenbmp, 0, edge_yoff);
5389 }
5390 }
5391
5392 //not the last column of screens
5393 if (peek_right)
5394 {
5395 if((screen&0x0F)<15 && !NoScreenPreview)
5396 {
5397 Map.drawcolumn(mapscreenbmp, right_col, edge_yoff, Flags, 0, -1, screen+1);
5398 }
5399 else
5400 {
5401 Map.drawstaticcolumn(mapscreenbmp, right_col, edge_yoff);
5402 }
5403 }
5404
5405 //not the first row or first column of screens
5406 if (peek_above && peek_left)
5407 {
5408 if((screen>15)&&(screen&0x0F) && !NoScreenPreview)
5409 {
5410 Map.drawblock(mapscreenbmp, 0, 0, Flags, 175, -1, screen-17);
5411 }
5412 else
5413 {
5414 Map.drawstaticblock(mapscreenbmp, 0, 0);
5415 }
5416 }
5417
5418 //not the first row or last column of screens
5419 if (peek_above && peek_right)
5420 {
5421 if((screen>15)&&((screen&0x0F)<15) && !NoScreenPreview)
5422 {
5423 Map.drawblock(mapscreenbmp, right_col, 0, Flags, 160, -1, screen-15);
5424 }
5425 else
5426 {
5427 Map.drawstaticblock(mapscreenbmp, right_col, 0);
5428 }
5429 }
5430
5431 //not the last row or first column of screens
5432 if (peek_below && peek_left)
5433 {
5434 if((screen<112)&&(screen&0x0F) && !NoScreenPreview)
5435 {
5436 Map.drawblock(mapscreenbmp, 0, bottom_row, Flags, 15, -1, screen+15);
5437 }
5438 else
5439 {
5440 Map.drawstaticblock(mapscreenbmp, 0, bottom_row);
5441 }
5442 }
5443
5444 //not the last row or last column of screens
5445 if (peek_below && peek_right)
5446 {
5447 if((screen<112)&&((screen&0x0F)<15) && !NoScreenPreview)
5448 {
5449 Map.drawblock(mapscreenbmp, right_col, bottom_row, Flags, 0, -1, screen+17);
5450 }
5451 else
5452 {
5453 Map.drawstaticblock(mapscreenbmp, right_col, bottom_row);
5454 }
5455 }
5456 }
5457
5458 if (ShowSquares && Map.getViewSize() < 4)
5459 {
5460 if(scr->stairx || scr->stairy)
5461 {
5462 int32_t x1 = scr->stairx+edge_xoff;
5463 int32_t y1 = scr->stairy+edge_yoff;
5464 safe_rect(mapscreenbmp,x1,y1,x1+15,y1+15,vc(14));
5465 }
5466
5467 if(scr->warparrivalx || scr->warparrivaly)
5468 {
5469 int32_t x1 = scr->warparrivalx +edge_xoff;
5470 int32_t y1 = scr->warparrivaly +edge_yoff;
5471 safe_rect(mapscreenbmp,x1,y1,x1+15,y1+15,vc(10));
5472 }
5473
5474 for(int32_t i=0; i<4; i++) if(scr->warpreturnx[i] || scr->warpreturny[i])
5475 {
5476 int32_t x1 = scr->warpreturnx[i]+edge_xoff;
5477 int32_t y1 = scr->warpreturny[i]+edge_yoff;
5478 int32_t clr = vc(9);
5479
5480 if(FlashWarpSquare==i)
5481 {
5482 if(!FlashWarpClk)
5483 FlashWarpSquare=-1;
5484 else if(!(--FlashWarpClk%3))
5485 clr = vc(15);
5486 }
5487
5488 safe_rect(mapscreenbmp,x1,y1,x1+15,y1+15,clr);
5489 }
5490 }
5491
5492 if(ShowFFCs)
5493 {
5494 mapscr* ffscr = prv_mode ? Map.get_prvscr() : scr;
5495 int num_ffcs = ffscr->numFFC();
5496 for(int32_t i=num_ffcs-1; i>=0; i--)
5497 {
5498 ffcdata& ff = ffscr->ffcs[i];
5499 if(ff.data !=0 && (ff.layer >= CurrentLayer || (ff.flags&ffc_overlay)))
5500 {
5501 auto x = ff.x+edge_xoff;
5502 auto y = ff.y+edge_yoff;
5503 safe_rect(mapscreenbmp, x+0, y+0, x+ff.txsz*16-1, y+ff.tysz*16-1, vc(12));
5504 }
5505 }
5506 }
5507
5508 if(!(Flags&cDEBUG) && pixeldb==1)
5509 {
5510 for(int32_t j=168; j<176; j++)
5511 {
5512 for(int32_t i=0; i<256; i++)
5513 {
5514 if(((i^j)&1)==0)
5515 {
5516 putpixel(mapscreenbmp,edge_xoff+i,
5517 edge_yoff+j,vc(blackout_color));
5518 }
5519 }
5520 }
5521 }
5522
5523 int w = mapscreenbmp->w * mapscreen_single_scale;
5524 int h = mapscreenbmp->h * mapscreen_single_scale;
5525 stretch_blit(mapscreenbmp, menu1, 0, 0, mapscreenbmp->w, mapscreenbmp->h, mapscreen_x + xoff, mapscreen_y + yoff, w, h);
5526 }
5527
5528 void draw_screenunit(int32_t unit, int32_t flags)
5529 {
5530 FONT* tfont = font;
5531 switch(unit)
5532 {
5533 case rSCRMAP:
5534 {
5535 size_and_pos *mini_sqr = &minimap;
5536 size_and_pos *real_mini_sqr = &real_minimap;
5537
5538 if(zoomed_minimap)
5539 {
5540 mini_sqr = &minimap_zoomed;
5541 real_mini_sqr = &real_minimap_zoomed;
5542 }
5543
5544 auto txt_x = real_mini_sqr->x+2+8*real_mini_sqr->xscale;
5545 auto txt_y = real_mini_sqr->y+2+8*real_mini_sqr->yscale;
5546
5547 rectfill(menu1, mini_sqr->x-1, mini_sqr->y-2,mini_sqr->x+mini_sqr->w-1,mini_sqr->y+mini_sqr->h-1,jwin_pal[jcBOX]);
5548 if(zoomed_minimap)
5549 jwin_draw_frame(menu1, mini_sqr->x-1, mini_sqr->y-2,mini_sqr->w,mini_sqr->h,FR_WIN);
5550 jwin_draw_minimap_frame(menu1,real_mini_sqr->x,real_mini_sqr->y,real_mini_sqr->tw(), real_mini_sqr->th(), real_mini_sqr->xscale, FR_DEEP);
5551
5552 if(Map.getCurrMap()<Map.getMapCount())
5553 {
5554 for(int32_t i=0; i<MAPSCRS; i++)
5555 {
5556 auto& sqr = real_mini_sqr->subsquare(i);
5557
5558 if(Map.Scr(i)->valid&mVALID)
5559 {
5560 // Handled by mmap_draw.
5561 }
5562 else
5563 {
5564 if (InvalidBG == 2)
5565 {
5566 draw_checkerboard(menu1, sqr.x, sqr.y, sqr.w);
5567 }
5568 else if (InvalidBG == 1)
5569 {
5570 for(int32_t dy=0; dy<sqr.h; dy++)
5571 {
5572 for(int32_t dx=0; dx<sqr.w; dx++)
5573 {
5574 menu1->line[dy+sqr.y][dx+sqr.x]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
5575 }
5576 }
5577 }
5578 else
5579 {
5580 int32_t offs = 2*(sqr.w/9);
5581 draw_x(menu1, sqr.x+offs, sqr.y+offs, sqr.x+sqr.w-1-offs, sqr.y+sqr.h-1-offs, vc(15));
5582 }
5583 }
5584 }
5585
5586 int32_t s=Map.getCurrScr();
5587
5588 BITMAP* txtbmp = create_bitmap_ex(8,256,64);
5589 clear_bitmap(txtbmp);
5590 int txtscale = zoomed_minimap ? (is_compact ? 2 : 3) : 1;
5591 font = get_zc_font(font_lfont_l);
5592
5593 int32_t space = text_length(font, "255")+2, spc_s = text_length(font, "S")+2, spc_m = text_length(font, "M")+2;
5594 textprintf_disabled(txtbmp,font,0,0,jwin_pal[jcLIGHT],jwin_pal[jcMEDDARK],"M");
5595 static int map_shortcut_tooltip_id = ttip_register_id();
5596 ttip_install(map_shortcut_tooltip_id, "Prev map: ,\nNext map: .", txt_x, txt_y, 30, 20, txt_x, txt_y - 60);
5597
5598 textprintf_ex(txtbmp,font,spc_m,0,jwin_pal[jcBOXFG],jwin_pal[jcBOX],"%-3d",Map.getCurrMap()+1);
5599
5600 textprintf_disabled(txtbmp,font,spc_m+space,0,jwin_pal[jcLIGHT],jwin_pal[jcMEDDARK],"S");
5601 textprintf_ex(txtbmp,font,spc_m+space+spc_s,0,jwin_pal[jcBOXFG],jwin_pal[jcBOX],"0x%02X (%d)",s, s);
5602 masked_stretch_blit(txtbmp, menu1, 0, 0, 256, 64, txt_x, txt_y, 256*txtscale, 64*txtscale);
5603 destroy_bitmap(txtbmp);
5604 }
5605 }
5606 break;
5607 case rMAP:
5608 {
5609 refresh_visible_screens();
5610 mapscreen_single_scale = (double)mapscreen_screenunit_scale / Map.getViewSize();
5611
5612 int num_combos_width = 16 * Map.getViewSize();
5613 int num_combos_height = 11 * Map.getViewSize();
5614
5615 if(CurrentLayer > 0 && !mapscreen_valid_layers[CurrentLayer-1])
5616 CurrentLayer = 0;
5617
5618 for (auto& vis_screen : visible_screens)
5619 {
5620 draw_screenunit_map_screen(vis_screen);
5621 }
5622
5623 if (showxypos_icon)
5624 {
5625 int x0 = showxypos_x + (showedges?16:0);
5626 int y0 = showxypos_y + (showedges?16:0);
5627 int x1 = x0 + showxypos_w - 1;
5628 int y1 = y0 + showxypos_h - 1;
5629 x0 *= mapscreen_single_scale;
5630 y0 *= mapscreen_single_scale;
5631 x1 *= mapscreen_single_scale;
5632 y1 *= mapscreen_single_scale;
5633 x0 += mapscreen_x;
5634 y0 += mapscreen_y;
5635 x1 += mapscreen_x;
5636 y1 += mapscreen_y;
5637
5638 if (showxypos_color == vc(15))
5639 safe_rect(menu1, x0, y0, x1, y1, showxypos_color);
5640 else
5641 rectfill(menu1, x0, y0, x1, y1, showxypos_color);
5642 }
5643
5644 if(showxypos_cursor_icon)
5645 {
5646 int x0 = showxypos_cursor_x + (showedges?16:0);
5647 int y0 = showxypos_cursor_y + (showedges?16:0);
5648 int x1 = x0 + showxypos_w - 1;
5649 int y1 = y0 + showxypos_h - 1;
5650 x0 *= mapscreen_single_scale;
5651 y0 *= mapscreen_single_scale;
5652 x1 *= mapscreen_single_scale;
5653 y1 *= mapscreen_single_scale;
5654 x0 += mapscreen_x;
5655 y0 += mapscreen_y;
5656 x1 += mapscreen_x;
5657 y1 += mapscreen_y;
5658 safe_rect(menu1, x0, y0, x1, y1, showxypos_cursor_color);
5659 }
5660
5661 // Draw dithering over the edge/preview combos.
5662 if(showedges)
5663 {
5664 int tile_size = 16 * mapscreen_single_scale;
5665 int tiles_across = (16 * Map.getViewSize()) + 2;
5666 int bottom_row_y = (Map.getViewSize()*11 + 1) * tile_size;
5667 int right_col_x = (Map.getViewSize()*16 + 1) * tile_size;
5668
5669 //top preview
5670 for(int32_t j=0; j<tile_size; j++)
5671 {
5672 for(int32_t i=0; i<tiles_across * tile_size; i++)
5673 {
5674 if(((i^j)&1)==0)
5675 {
5676 putpixel(menu1,mapscreen_x+i,mapscreen_y+j,vc(0));
5677 }
5678 }
5679 }
5680
5681 //bottom preview
5682 for(int32_t j = bottom_row_y; j < bottom_row_y + tile_size; j++)
5683 {
5684 for(int32_t i=0; i<tiles_across * tile_size; i++)
5685 {
5686 if(((i^j)&1)==0)
5687 {
5688 putpixel(menu1,mapscreen_x+i,mapscreen_y+j,vc(0));
5689 }
5690 }
5691 }
5692
5693 //left preview
5694 for(int32_t j=tile_size; j<int32_t(192*mapscreen_screenunit_scale); j++)
5695 {
5696 for(int32_t i=0; i<16*mapscreen_single_scale; i++)
5697 {
5698 if(((i^j)&1)==0)
5699 {
5700 putpixel(menu1,mapscreen_x+i,mapscreen_y+j,vc(0));
5701 }
5702 }
5703 }
5704
5705 //right preview
5706 for(int32_t j=tile_size; j<int32_t(192*mapscreen_screenunit_scale); j++)
5707 {
5708 for(int32_t i = right_col_x; i < right_col_x + tile_size; i++)
5709 {
5710 if(((i^j)&1)==0)
5711 {
5712 putpixel(menu1,mapscreen_x+i,mapscreen_y+j,vc(0));
5713 }
5714 }
5715 }
5716 }
5717
5718 if(!(Flags&cDEBUG) && pixeldb==2)
5719 {
5720 for(int32_t j=int32_t(168*mapscreen_single_scale); j<int32_t(176*mapscreen_single_scale); j++)
5721 {
5722 for(int32_t i=0; i<int32_t(256*mapscreen_single_scale); i++)
5723 {
5724
5725 if(((i^j)&1)==0)
5726 {
5727 putpixel(menu1,int32_t(mapscreen_x+(showedges?(16*mapscreen_single_scale):0)+i),
5728 int32_t(mapscreen_y+(showedges?(16*mapscreen_single_scale):0)+j),vc(blackout_color));
5729 }
5730 }
5731 }
5732 }
5733
5734 // TODO: This should move to `zmap::draw` (and delete the current code there doing a similar thing).
5735 if (Map.isDark(Map.getCurrScr()) && Map.getViewSize() == 1)
5736 {
5737 if((Flags&cNEWDARK) && get_qr(qr_NEW_DARKROOM))
5738 {
5739 BITMAP* tmpDark = create_bitmap_ex(8,16*16,16*11);
5740 BITMAP* tmpDarkTrans = create_bitmap_ex(8,16*16,16*11);
5741 BITMAP* tmpbuf = create_bitmap_ex(8,
5742 mapscreen_single_scale*(256+(showedges?32:0)),
5743 mapscreen_single_scale*(176+(showedges?32:0)));
5744 BITMAP* tmpbuf2 = create_bitmap_ex(8,
5745 mapscreen_single_scale*(256+(showedges?32:0)),
5746 mapscreen_single_scale*(176+(showedges?32:0)));
5747 int32_t darkCol = zinit.darkcol;
5748 switch(darkCol) //special cases
5749 {
5750 case BLACK:
5751 darkCol = vc(0);
5752 break;
5753 case WHITE:
5754 darkCol = vc(15);
5755 break;
5756 }
5757 clear_to_color(tmpDark, darkCol);
5758 clear_to_color(tmpDarkTrans, darkCol);
5759 clear_bitmap(tmpbuf);
5760 clear_bitmap(tmpbuf2);
5761 //Handle torch combos
5762 color_map = &trans_table2;
5763 Map.draw_darkness(tmpDark, tmpDarkTrans);
5764 //
5765 mapscr* tmp = Map.CurrScr();
5766 if(tmp->flags9 & fDARK_DITHER)
5767 {
5768 ditherblit(tmpDark, tmpDark, 0, zinit.dither_type, zinit.dither_arg);
5769 ditherblit(tmpDarkTrans, tmpDarkTrans, 0, zinit.dither_type, zinit.dither_arg);
5770 }
5771
5772 if(mapscreen_single_scale == 1)
5773 {
5774 blit(tmpDark, tmpbuf, 0, 0, (showedges?16:0), (showedges?16:0), 16*16, 16*11);
5775 blit(tmpDarkTrans, tmpbuf2, 0, 0, (showedges?16:0), (showedges?16:0), 16*16, 16*11);
5776 }
5777 else
5778 {
5779 stretch_blit(tmpDark, tmpbuf, 0, 0, 16*16, 16*11,
5780 (showedges?16:0)*mapscreen_single_scale, (showedges?16:0)*mapscreen_single_scale,
5781 (16*16)*mapscreen_single_scale, (16*11)*mapscreen_single_scale);
5782 stretch_blit(tmpDarkTrans, tmpbuf2, 0, 0, 16*16, 16*11,
5783 (showedges?16:0)*mapscreen_single_scale, (showedges?16:0)*mapscreen_single_scale,
5784 (16*16)*mapscreen_single_scale, (16*11)*mapscreen_single_scale);
5785 }
5786
5787 if(tmp->flags9 & fDARK_TRANS)
5788 {
5789 draw_trans_sprite(menu1, tmpbuf, mapscreen_x, mapscreen_y);
5790 }
5791 else
5792 {
5793 masked_blit(tmpbuf,menu1,0,0,mapscreen_x,mapscreen_y,tmpbuf->w,tmpbuf->h);
5794 }
5795 draw_trans_sprite(menu1, tmpbuf2, mapscreen_x, mapscreen_y);
5796 color_map = &trans_table;
5797 //
5798 destroy_bitmap(tmpDark);
5799 destroy_bitmap(tmpDarkTrans);
5800 destroy_bitmap(tmpbuf);
5801 destroy_bitmap(tmpbuf2);
5802 }
5803 else if(!(Flags&cNODARK))
5804 {
5805 for(int32_t j=0; j<80*mapscreen_single_scale; j++)
5806 {
5807 for(int32_t i=0; i<(80*mapscreen_single_scale)-j; i++)
5808 {
5809 if(((i^j)&1)==0)
5810 {
5811 putpixel(menu1,int32_t(mapscreen_x+(showedges?(16*mapscreen_single_scale):0))+i,
5812 int32_t(mapscreen_y+(showedges?(16*mapscreen_single_scale):0)+j),vc(blackout_color));
5813 }
5814 }
5815 }
5816 }
5817 }
5818
5819 double startx=mapscreen_x+(showedges?(16*mapscreen_single_scale):0);
5820 double starty=mapscreen_y+(showedges?(16*mapscreen_single_scale):0);
5821 bool inrect = isinRect(gui_mouse_x(),gui_mouse_y(),startx,starty,(startx+(256*mapscreen_screenunit_scale)-1),(starty+(176*mapscreen_screenunit_scale)-1));
5822
5823 if(!(flags&rNOCURSOR) && ((ComboBrush && !ComboBrushPause)||draw_mode==dm_alias) && inrect)
5824 {
5825 int mgridscale=16*mapscreen_single_scale;
5826 if(allowHideMouse)
5827 {
5828 if(arrowcursor)
5829 {
5830 arrowcursor = false;
5831 MouseSprite::set(ZQM_BLANK);
5832 }
5833 }
5834 else if(!arrowcursor)
5835 {
5836 arrowcursor = true;
5837 MouseSprite::set(ZQM_NORMAL);
5838 }
5839 ComboPosition pos = get_mapscreen_mouse_combo_pos();
5840 int32_t mx = pos.x * 16 * mapscreen_single_scale;
5841 int32_t my = pos.y * 16 * mapscreen_single_scale;
5842
5843 clear_bitmap(brushscreen);
5844 int32_t tempbw=BrushWidth;
5845 int32_t tempbh=BrushHeight;
5846
5847 if(draw_mode==dm_alias)
5848 {
5849 BrushWidth = combo_aliases[combo_apos].width+1;
5850 BrushHeight = combo_aliases[combo_apos].height+1;
5851 }
5852 else if(draw_mode == dm_cpool)
5853 {
5854 BrushWidth = BrushHeight = 1;
5855 combo_pool const& pool = combo_pools[combo_pool_pos];
5856 if(pool.valid())
5857 {
5858 int32_t cid = Combo;
5859 int8_t cset = CSet;
5860 pool.get_w_wrap(cid,cset,cpoolbrush_index/16); //divide to reduce speed
5861 put_combo(brushbmp,0,0,cid,cset,Flags&(cFLAGS|cWALK),0);
5862 }
5863 else clear_bitmap(brushbmp);
5864 }
5865 else if (draw_mode == dm_auto)
5866 {
5867 BrushWidth = BrushHeight = 1;
5868 }
5869
5870 stretch_blit(brushbmp, brushscreen, 0, 0, BrushWidth*16, BrushHeight*16, 0, 0, BrushWidth*mgridscale, BrushHeight*mgridscale);
5871 int float_offx = 0;
5872 int float_offy = 0;
5873
5874 if(FloatBrush)
5875 {
5876 float_offx = -SHADOW_DEPTH*mapscreen_single_scale;
5877 float_offy = -SHADOW_DEPTH*mapscreen_single_scale;
5878
5879 //shadow
5880 for(int x = 0; x < SHADOW_DEPTH*mapscreen_single_scale; ++x)
5881 for(int y = 0; y < (BrushHeight*mgridscale) + (SHADOW_DEPTH*mapscreen_single_scale); ++y)
5882 {
5883 if((((x^y)&1)==1) && y < 12*mgridscale)
5884 putpixel(brushscreen,x+(BrushWidth*mgridscale),y,vc(0));
5885 }
5886
5887 for(int x = 0; x < BrushWidth*mgridscale; ++x)
5888 for(int y = 0; y < SHADOW_DEPTH*mapscreen_single_scale; ++y)
5889 {
5890 if((((x^y)&1)==1) && x<16*mgridscale)
5891 putpixel(brushscreen,x,y+(BrushHeight*mgridscale),vc(0));
5892 }
5893 }
5894
5895 if(draw_mode==dm_alias)
5896 {
5897 combo_alias *combo = &combo_aliases[combo_apos];
5898
5899 if(BrushWidth > 1 && (alias_origin & 1)) //right-align
5900 float_offx -= (BrushWidth - 1) * mgridscale;
5901
5902 if(BrushHeight > 1 && (alias_origin & 2)) //bottom-align
5903 float_offy -= (BrushHeight - 1) * mgridscale;
5904 }
5905
5906 int bx = mapscreen_x + mx + float_offx + (showedges?(16*mapscreen_single_scale):0);
5907 int by = mapscreen_y + my + float_offy + (showedges?(16*mapscreen_single_scale):0);
5908 masked_blit(brushscreen, menu1, 0, 0, bx, by, 16*mgridscale, 11*mgridscale);
5909 BrushWidth=tempbw;
5910 BrushHeight=tempbh;
5911 }
5912 else
5913 {
5914 if(!arrowcursor)
5915 {
5916 MouseSprite::set(ZQM_NORMAL);
5917 arrowcursor = true;
5918 }
5919 }
5920
5921 int startxint = mapscreen_x+(showedges?int(16*mapscreen_single_scale):0);
5922 int startyint = mapscreen_y+(showedges?int(16*mapscreen_single_scale):0);
5923 int endxint = startx + 256*mapscreen_screenunit_scale - 1;
5924 int endyint = starty + 176*mapscreen_screenunit_scale - 1;
5925 set_clip_rect(menu1,startxint,startyint,endxint,endyint);
5926
5927 if(ShowGrid)
5928 {
5929 int w = num_combos_width;
5930 int h = num_combos_height;
5931 double tile_size = 16.0 / Map.getViewSize() * mapscreen_screenunit_scale;
5932
5933 if(showedges)
5934 {
5935 w += 2;
5936 h += 2;
5937 }
5938
5939 for (int x = 1; x < w; x++)
5940 {
5941 vline(menu1, mapscreen_x + x*tile_size, mapscreen_y, mapscreen_y + (h*tile_size)-1, vc(GridColor));
5942 }
5943
5944 for (int y = 1; y < h; y++)
5945 {
5946 hline(menu1, mapscreen_x, mapscreen_y + y*tile_size, mapscreen_x + (w*tile_size)-1, vc(GridColor));
5947 }
5948 }
5949
5950 if(ShowScreenGrid)
5951 {
5952 int w = num_combos_width;
5953 int h = num_combos_height;
5954 double tile_size = 16.0 / Map.getViewSize() * mapscreen_screenunit_scale;
5955 int startx = mapscreen_x + (showedges ? (16 * mapscreen_single_scale) : 0);
5956 int starty = mapscreen_y + (showedges ? (16 * mapscreen_single_scale) : 0);
5957
5958 if(showedges)
5959 {
5960 w += 1;
5961 h += 1;
5962 }
5963
5964 int color = (GridColor+8)%16;
5965
5966 for (int x = 16; x < w; x+=16)
5967 {
5968 vline(menu1, startx + x*tile_size, mapscreen_y, starty + (h*tile_size)-1, vc(color));
5969 }
5970
5971 for (int y = 11; y < h; y+=11)
5972 {
5973 hline(menu1, startx, starty + y*tile_size, startx + (w*tile_size)-1, vc(color));
5974 }
5975 }
5976
5977 // Draw a rect around regions.
5978 if (ShowRegionGrid && Map.getViewSize() > 1)
5979 {
5980 for (const auto& region_description : Map.get_region_descriptions())
5981 {
5982 int sx = region_description.screen % 16;
5983 int sy = region_description.screen / 16;
5984 int sw = region_description.w;
5985 int sh = region_description.h;
5986
5987 int mw = 256 * mapscreen_single_scale;
5988 int mh = 176 * mapscreen_single_scale;
5989 int mx = sx - (Map.getViewScr() % 16);
5990 int my = sy - (Map.getViewScr() / 16);
5991 int x0 = mapscreen_x + (showedges ? (16 * mapscreen_single_scale) : 0) + mx * mw;
5992 int y0 = mapscreen_y + (showedges ? (16 * mapscreen_single_scale) : 0) + my * mh;
5993 rect(menu1, x0+2, y0+2, x0 + mw*sw - 2, y0 + mh*sh - 2, vc(1));
5994 rect(menu1, x0+1, y0+1, x0 + mw*sw - 1, y0 + mh*sh - 1, vc(15));
5995 rect(menu1, x0, y0, x0 + mw*sw, y0 + mh*sh, vc(1));
5996 }
5997 }
5998
5999 // Draw a black-yellow-black rect around the currently selected screen.
6000 if (ShowCurScreenOutline && Map.getViewSize() > 1)
6001 {
6002 int mw = 256 * mapscreen_single_scale;
6003 int mh = 176 * mapscreen_single_scale;
6004 int mx = (Map.getCurrScr() % 16) - (Map.getViewScr() % 16);
6005 int my = (Map.getCurrScr() / 16) - (Map.getViewScr() / 16);
6006 int x0 = mapscreen_x + (showedges ? (16 * mapscreen_single_scale) : 0) + mx * mw;
6007 int y0 = mapscreen_y + (showedges ? (16 * mapscreen_single_scale) : 0) + my * mh;
6008 dotted_rect(menu1, x0+2, y0+2, x0 + mw - 2, y0 + mh - 2, vc(1), vc(0));
6009 rect(menu1, x0+1, y0+1, x0 + mw - 1, y0 + mh - 1, vc(14));
6010 dotted_rect(menu1, x0, y0, x0 + mw, y0 + mh, vc(1), vc(0));
6011 }
6012
6013 clear_clip_rect(menu1);
6014
6015 // Map tabs
6016 font = get_custom_font(CFONT_GUI);
6017
6018 map_page[current_mappage].map=Map.getCurrMap();
6019 map_page[current_mappage].screen=Map.getCurrScr();
6020
6021 for(int32_t btn=0; btn<mappage_count; ++btn)
6022 {
6023 char tbuf[15];
6024 sprintf(tbuf, "%d:%02X", map_page[btn].map+1, map_page[btn].screen);
6025 draw_layer_button(menu1,map_page_bar[btn].x, map_page_bar[btn].y, map_page_bar[btn].w, map_page_bar[btn].h,tbuf,(btn==current_mappage?D_SELECTED:0));
6026 }
6027 }
6028 break;
6029 case rCOMBOS:
6030 {
6031 auto real_h = combolist_window.h;
6032 jwin_draw_frame(menu1,combolist_window.x,combolist_window.y,combolist_window.w,real_h, FR_WIN);
6033 rectfill(menu1,combolist_window.x+2,combolist_window.y+2,combolist_window.x+combolist_window.w-3,combolist_window.y+real_h-3,jwin_pal[jcBOX]);
6034
6035 //Scrollers
6036 for(int32_t c = 0; c < num_combo_cols; ++c)
6037 {
6038 auto& pos = combolistscrollers[c];
6039
6040 { //Scroll up
6041 auto& p = pos.subsquare(0);
6042 jwin_draw_frame(menu1,p.x,p.y,p.w,p.h,FR_ETCHED);
6043
6044 for(int32_t i=0; i<3; i++)
6045 {
6046 hline(menu1, p.x+5-i, p.y+4+i, p.x+5+i, jwin_pal[jcBOXFG]);
6047 }
6048 }
6049
6050 { //Scroll down
6051 auto& p = pos.subsquare(1);
6052 jwin_draw_frame(menu1,p.x,p.y,p.w,p.h,FR_ETCHED);
6053
6054 for(int32_t i=0; i<3; i++)
6055 {
6056 hline(menu1,p.x+5-i,p.y+6-i, p.x+5+i, jwin_pal[jcBOXFG]);
6057 }
6058 }
6059 }
6060
6061 if(draw_mode==dm_alias)
6062 {
6063 if(LinkedScroll)
6064 {
6065 int tmp = current_comboalist;
6066 for(int q = tmp-1; q >= 0; --q)
6067 {
6068 combo_alistpos[q] = combo_alistpos[q+1]-(comboaliaslist[q].w*comboaliaslist[q].h);
6069 if(combo_alistpos[q] < 0)
6070 {
6071 tmp = 0;
6072 combo_alistpos[0] = 0;
6073 break;
6074 }
6075 }
6076 for(int q = tmp+1; q < num_combo_cols; ++q)
6077 combo_alistpos[q] = combo_alistpos[q-1]+(comboaliaslist[q-1].w*comboaliaslist[q-1].h);
6078 for(int q = 0; q < num_combo_cols; ++q)
6079 if(combo_apos >= combo_alistpos[q] && combo_apos < combo_alistpos[q] + (comboaliaslist[q].w*comboaliaslist[q].h))
6080 {
6081 current_comboalist = q;
6082 break;
6083 }
6084 }
6085 for(int32_t c = 0; c < num_combo_cols; ++c)
6086 {
6087 auto& pos = comboaliaslist[c];
6088 rectfill(menu1,pos.x,pos.y,pos.x+(pos.w*pos.xscale)-1,pos.y+(pos.h*pos.yscale)-1,0);
6089 jwin_draw_frame(menu1,pos.x-2,pos.y-2,(pos.w*pos.xscale)+4,(pos.h*pos.yscale)+4,FR_DEEP);
6090 }
6091
6092 auto& prev = comboalias_preview;
6093 jwin_draw_frame(menu1, prev.x-2, prev.y-2, prev.w+4, prev.h+4,FR_DEEP);
6094
6095 BITMAP *prv = create_bitmap_ex(8,64,64);
6096 clear_bitmap(prv);
6097 int32_t scalefactor = 1;
6098
6099 for(int32_t j=0; j<num_combo_cols; ++j)
6100 {
6101 auto per_page = (comboaliaslist[j].w * comboaliaslist[j].h);
6102 if(combo_alistpos[j] + per_page >= MAXCOMBOALIASES)
6103 combo_alistpos[j] = MAXCOMBOALIASES-per_page;
6104 auto& col = comboaliaslist[j];
6105 for(int32_t i=0; i<(comboaliaslist[j].w*comboaliaslist[j].h); i++)
6106 {
6107 draw_combo_alias_thumbnail(menu1, &combo_aliases[combo_alistpos[j]+i],
6108 (i%col.w)*col.xscale+col.x, (i/col.w)*col.yscale+col.y, col.xscale/16);
6109 }
6110
6111 if((combo_aliases[combo_apos].width>7)||(combo_aliases[combo_apos].height>7))
6112 {
6113 scalefactor=4;
6114 }
6115 else if((combo_aliases[combo_apos].width>3)||(combo_aliases[combo_apos].height>3))
6116 {
6117 scalefactor=2;
6118 }
6119
6120
6121 if(j==current_comboalist)
6122 {
6123 stretch_blit(brushbmp, prv, 0,0,scalefactor*64,zc_min(scalefactor*64,176),0,0,64,scalefactor==4?44:64);
6124 blit(prv,menu1,0,0,comboalias_preview.x,comboalias_preview.y,comboalias_preview.w,comboalias_preview.h);
6125
6126 int32_t rect_pos=combo_apos-combo_alistpos[current_comboalist];
6127
6128 if((rect_pos>=0)&&(rect_pos<(combo_alistpos[current_comboalist]+(col.w*col.h))))
6129 {
6130 int selw = col.xscale;
6131 int selh = col.yscale;
6132 int x1 = (rect_pos&(col.w-1))*col.xscale+col.x;
6133 int y1 = (rect_pos/col.w)*col.yscale+col.y;
6134 safe_rect(menu1,x1,y1,x1+selw-1,y1+selh-1,vc(CmbCursorCol),2);
6135 }
6136 }
6137 }
6138
6139 destroy_bitmap(prv);
6140 }
6141 else if(draw_mode==dm_cpool)
6142 {
6143 if(LinkedScroll)
6144 {
6145 int tmp = current_cpoollist;
6146 for(int q = tmp-1; q >= 0; --q)
6147 {
6148 combo_pool_listpos[q] = combo_pool_listpos[q+1]-(comboaliaslist[q].w*comboaliaslist[q].h);
6149 if(combo_pool_listpos[q] < 0)
6150 {
6151 tmp = 0;
6152 combo_pool_listpos[0] = 0;
6153 break;
6154 }
6155 }
6156 for(int q = tmp+1; q < num_combo_cols; ++q)
6157 combo_pool_listpos[q] = combo_pool_listpos[q-1]+(comboaliaslist[q-1].w*comboaliaslist[q-1].h);
6158 for(int q = 0; q < num_combo_cols; ++q)
6159 if(combo_pool_pos >= combo_pool_listpos[q] && combo_pool_pos < combo_pool_listpos[q] + (comboaliaslist[q].w*comboaliaslist[q].h))
6160 {
6161 current_cpoollist = q;
6162 break;
6163 }
6164 }
6165 for(int32_t c = 0; c < num_combo_cols; ++c)
6166 {
6167 auto& pos = comboaliaslist[c];
6168 rectfill(menu1,pos.x,pos.y,pos.x+(pos.w*pos.xscale)-1,pos.y+(pos.h*pos.yscale)-1,0);
6169 jwin_draw_frame(menu1,pos.x-2,pos.y-2,(pos.w*comboaliaslist[c].xscale)+4,(pos.h*comboaliaslist[c].yscale)+4,FR_DEEP);
6170 }
6171
6172 for (int32_t j = 0; j < num_combo_cols; ++j) //the actual panes
6173 {
6174 auto per_page = (comboaliaslist[j].w * comboaliaslist[j].h);
6175 if(combo_pool_listpos[j] + per_page >= MAXCOMBOPOOLS)
6176 combo_pool_listpos[j] = MAXCOMBOPOOLS-per_page;
6177 for(int32_t i=0; i<(comboaliaslist[j].w*comboaliaslist[j].h); i++)
6178 {
6179 int32_t cid=-1; int8_t cs=CSet;
6180 combo_pool const& cp = combo_pools[combo_pool_listpos[j]+i];
6181
6182 auto& list = comboaliaslist[j];
6183 if(cp.get_w(cid,cs,0) && !combobuf[cid].tile)
6184 {
6185 cid = -1; //no tile to draw
6186 }
6187 auto cx = (i%list.w)*list.xscale+list.x;
6188 auto cy = (i/list.w)*list.yscale+list.y;
6189 put_combo(menu1,cx,cy,cid,cs,Flags&(cFLAGS|cWALK),0,list.xscale/16);
6190 }
6191 }
6192 int32_t rect_pos=combo_pool_pos-combo_pool_listpos[current_cpoollist];
6193
6194 if((rect_pos>=0)&&(rect_pos<(combo_pool_listpos[current_cpoollist]+(comboaliaslist[current_cpoollist].w*comboaliaslist[current_cpoollist].h))))
6195 {
6196 int selw = comboaliaslist[current_cpoollist].xscale;
6197 int selh = comboaliaslist[current_cpoollist].yscale;
6198 int x1 = (rect_pos&(comboaliaslist[current_cpoollist].w-1))*comboaliaslist[current_cpoollist].xscale+comboaliaslist[current_cpoollist].x;
6199 int y1 = (rect_pos/comboaliaslist[current_cpoollist].w)*comboaliaslist[current_cpoollist].yscale+comboaliaslist[current_cpoollist].y;
6200 safe_rect(menu1,x1,y1,x1+selw-1,y1+selh-1,vc(CmbCursorCol),2);
6201 }
6202
6203 //Handle Preview
6204 combo_pool const& cpool = combo_pools[combo_pool_pos];
6205
6206 int32_t cid; int8_t cs;
6207 size_t total = weighted_cpool ? cpool.getTotalWeight() : cpool.combos.size();
6208 size_t ind = 0;
6209 size_t indw = combopool_preview.w/16;
6210 size_t indh = combopool_preview.h/16;
6211 size_t rows = total ? vbound(total/indw,1,indh) : 0;
6212 if (is_compact)
6213 rows = vbound(rows, 1, 3);
6214 else
6215 rows = vbound(rows, 1, 4);
6216 size_t real_height = rows*16;
6217
6218 cpool_prev_visible = rows > 0;
6219 if(rows)
6220 {
6221 jwin_draw_frame(menu1,combopool_preview.x-2,combopool_preview.y-2,
6222 combopool_preview.w+4,real_height+4,FR_DEEP);
6223 rectfill(menu1,combopool_preview.x,combopool_preview.y,
6224 combopool_preview.x+combopool_preview.w-1,
6225 combopool_preview.y+real_height-1,vc(0));
6226 draw_text_button(menu1,combopool_prevbtn.x,combopool_prevbtn.y,
6227 combopool_prevbtn.w,combopool_prevbtn.h,
6228 weighted_cpool ? "Weighted" : "Unweighted",vc(1),vc(14),0,true);
6229 if(!is_compact)
6230 textprintf_ex(menu1,font,combopool_prevbtn.x+combopool_prevbtn.w+5,
6231 combopool_prevbtn.y,jwin_pal[jcBOXFG],-1,"Preview");
6232 for(auto y = 0; y < real_height; y += 16)
6233 {
6234 for(auto x = 0; x < combopool_preview.w; x += 16, ++ind)
6235 {
6236 auto nx = combopool_preview.x+x, ny = combopool_preview.y+y;
6237 if(ind < total)
6238 {
6239 cs = CSet;
6240 if(weighted_cpool
6241 ? cpool.get_w(cid,cs,ind)
6242 : cpool.get_ind(cid,cs,ind))
6243 {
6244 put_combo(menu1,nx,ny,cid,cs,Flags&(cFLAGS|cWALK),0);
6245 continue;
6246 }
6247 }
6248 //No combo to display
6249 xout(menu1, nx, ny, nx+15, ny+15, vc(15));
6250 }
6251 }
6252 }
6253 }
6254 else if (draw_mode == dm_auto)
6255 {
6256 if (LinkedScroll)
6257 {
6258 int tmp = current_cautolist;
6259 for (int q = tmp - 1; q >= 0; --q)
6260 {
6261 combo_auto_listpos[q] = combo_auto_listpos[q + 1] - (comboaliaslist[q].w * comboaliaslist[q].h);
6262 if (combo_auto_listpos[q] < 0)
6263 {
6264 tmp = 0;
6265 combo_auto_listpos[0] = 0;
6266 break;
6267 }
6268 }
6269 for (int q = tmp + 1; q < num_combo_cols; ++q)
6270 combo_auto_listpos[q] = combo_auto_listpos[q - 1] + (comboaliaslist[q - 1].w * comboaliaslist[q - 1].h);
6271 for (int q = 0; q < num_combo_cols; ++q)
6272 if (combo_auto_pos >= combo_auto_listpos[q] && combo_auto_pos < combo_auto_listpos[q] + (comboaliaslist[q].w * comboaliaslist[q].h))
6273 {
6274 current_cautolist = q;
6275 break;
6276 }
6277 }
6278 for (int32_t c = 0; c < num_combo_cols; ++c)
6279 {
6280 auto& pos = comboaliaslist[c];
6281 rectfill(menu1, pos.x, pos.y, pos.x + (pos.w * pos.xscale) - 1, pos.y + (pos.h * pos.yscale) - 1, 0);
6282 jwin_draw_frame(menu1, pos.x - 2, pos.y - 2, (pos.w * comboaliaslist[c].xscale) + 4, (pos.h * comboaliaslist[c].yscale) + 4, FR_DEEP);
6283 }
6284
6285 for (int32_t j = 0; j < num_combo_cols; ++j) //the actual panes
6286 {
6287 auto per_page = (comboaliaslist[j].w * comboaliaslist[j].h);
6288 if(combo_auto_listpos[j] + per_page >= MAXAUTOCOMBOS)
6289 combo_auto_listpos[j] = MAXAUTOCOMBOS-per_page;
6290 for (int32_t i = 0; i < (comboaliaslist[j].w * comboaliaslist[j].h); i++)
6291 {
6292 int32_t cid = -1; int8_t cs = CSet;
6293 combo_auto const& ca = combo_autos[combo_auto_listpos[j] + i];
6294
6295 auto& list = comboaliaslist[j];
6296 cid = ca.getDisplay();
6297 if (cid == 0)
6298 cid = -1;
6299 auto cx = (i % list.w) * list.xscale + list.x;
6300 auto cy = (i / list.w) * list.yscale + list.y;
6301 put_combo(menu1, cx, cy, cid, cs, Flags & (cFLAGS | cWALK), 0, list.xscale / 16);
6302 put_autocombo_engravings(menu1, ca, combo_auto_listpos[j] + i == combo_auto_pos, cx, cy, list.xscale / 16);
6303 }
6304 }
6305 int32_t rect_pos = combo_auto_pos - combo_auto_listpos[current_cautolist];
6306
6307 if ((rect_pos >= 0) && (rect_pos < (combo_auto_listpos[current_cautolist] + (comboaliaslist[current_cautolist].w * comboaliaslist[current_cautolist].h))))
6308 {
6309 int selw = comboaliaslist[current_cautolist].xscale;
6310 int selh = comboaliaslist[current_cautolist].yscale;
6311 int x1 = (rect_pos & (comboaliaslist[current_cautolist].w - 1)) * comboaliaslist[current_cautolist].xscale + comboaliaslist[current_cautolist].x;
6312 int y1 = (rect_pos / comboaliaslist[current_cautolist].w) * comboaliaslist[current_cautolist].yscale + comboaliaslist[current_cautolist].y;
6313 safe_rect(menu1, x1, y1, x1 + selw - 1, y1 + selh - 1, vc(CmbCursorCol), 2);
6314
6315 combo_auto const& ca = combo_autos[combo_auto_pos];
6316 put_autocombo_engravings(menu1, ca, true, x1, y1, selw / 16);
6317 }
6318 }
6319 else
6320 {
6321 if(LinkedScroll)
6322 {
6323 int tmp = current_combolist;
6324 for(int q = tmp-1; q >= 0; --q)
6325 {
6326 First[q] = First[q+1]-(combolist[q].w*combolist[q].h);
6327 if(First[q] < 0)
6328 {
6329 tmp = 0;
6330 First[0] = 0;
6331 break;
6332 }
6333 }
6334 for(int q = tmp+1; q < num_combo_cols; ++q)
6335 First[q] = First[q-1]+(combolist[q-1].w*combolist[q-1].h);
6336 for(int q = 0; q < num_combo_cols; ++q)
6337 if(Combo >= First[q] && Combo < First[q] + (combolist[q].w*combolist[q].h))
6338 {
6339 current_combolist = q;
6340 break;
6341 }
6342 }
6343 for(int32_t c = 0; c < num_combo_cols; ++c)
6344 {
6345 auto& pos = combolist[c];
6346 rectfill(menu1,pos.x,pos.y,pos.x+(pos.w*pos.xscale)-1,pos.y+(pos.h*pos.yscale)-1,0);
6347 jwin_draw_frame(menu1,pos.x-2,pos.y-2,(pos.w*pos.xscale)+4,(pos.h*pos.yscale)+4,FR_DEEP);
6348 }
6349
6350 int32_t drawmap, drawscr;
6351 drawmap=Map.CurrScr()->layermap[CurrentLayer-1]-1;
6352 drawscr=Map.CurrScr()->layerscreen[CurrentLayer-1];
6353
6354 for(int32_t j=0; j<num_combo_cols; ++j)
6355 {
6356 auto per_page = (combolist[j].w * combolist[j].h);
6357 if(First[j] + per_page >= MAXCOMBOS)
6358 First[j] = MAXCOMBOS-per_page;
6359 for(int32_t i=0; i<(combolist[j].w*combolist[j].h); i++)
6360 {
6361 put_combo(menu1,(i%combolist[j].w)*combolist[j].xscale+combolist[j].x,
6362 (i/combolist[j].w)*combolist[j].yscale+combolist[j].y,
6363 i+First[j],CSet,Flags&(cFLAGS|cWALK),0,combolist[j].xscale/16);
6364 }
6365 }
6366
6367 int32_t rect_pos=Combo-First[current_combolist];
6368
6369 if((rect_pos>=0)&&(rect_pos<(combo_pool_listpos[current_combolist]+(combolist[current_combolist].w*combolist[current_combolist].h))))
6370 {
6371 int selw = (AutoBrush?BrushWidth:1)*combolist[current_combolist].xscale;
6372 int selh = (AutoBrush?BrushHeight:1)*combolist[current_combolist].yscale;
6373 int x1 = (rect_pos&(combolist[current_combolist].w-1))*combolist[current_combolist].xscale+combolist[current_combolist].x;
6374 int y1 = (rect_pos/combolist[current_combolist].w)*combolist[current_combolist].yscale+combolist[current_combolist].y;
6375 safe_rect(menu1,x1,y1,x1+selw-1,y1+selh-1,vc(CmbCursorCol),2);
6376 }
6377 }
6378 }
6379 break;
6380 case rCOMBO:
6381 {
6382 int32_t drawmap, drawscr;
6383 drawmap=Map.CurrScr()->layermap[CurrentLayer-1]-1;
6384 drawscr=Map.CurrScr()->layerscreen[CurrentLayer-1];
6385
6386 // Combo preview
6387 int32_t cid = Combo; int8_t cs = CSet;
6388 if(draw_mode == dm_alias)
6389 {
6390 cid = combo_aliases[combo_apos].combos[0];
6391 cs = wrap(combo_aliases[combo_apos].csets[0]+alias_cset_mod, 0, 13);
6392 }
6393 else if(draw_mode == dm_cpool)
6394 {
6395 combo_pool const& cpool = combo_pools[combo_pool_pos];
6396 cid = 0;
6397 cpool.get_w(cid,cs,0);
6398 }
6399 else if (draw_mode == dm_auto)
6400 {
6401 combo_auto const& cauto = combo_autos[combo_auto_pos];
6402 cid = cauto.getDisplay();
6403 }
6404 static BITMAP *combo_preview_bmp=create_bitmap_ex(8,32,32);
6405 static BITMAP *cycle_preview_bmp=create_bitmap_ex(8,32,32);
6406 // Combo
6407 put_combo(combo_preview_bmp,0,0,cid,cs,Flags&(cFLAGS|cWALK),0);
6408 jwin_draw_frame(menu1,combo_preview.x-2,combo_preview.y-2,combo_preview.w+4,combo_preview.h+4, FR_DEEP);
6409 stretch_blit(combo_preview_bmp, menu1, 0, 0, 16, 16, combo_preview.x, combo_preview.y, combo_preview.w, combo_preview.h);
6410
6411 comboprev_buf[0] = 0;
6412 comboprev_buf2[0] = 0;
6413 if(draw_mode == dm_cpool)
6414 {
6415 sprintf(comboprev_buf,"Pool: %d\nCSet: %d",combo_pool_pos,CSet);
6416 int x = combo_preview_text1.x+(combo_preview_text1.w*combo_preview_text1.xscale);
6417 textbox_out(menu1,txfont,x,combo_preview_text1.y,jwin_pal[jcBOXFG],jwin_pal[jcBOX],comboprev_buf,2,&combo_preview_text1);
6418 }
6419 else if (draw_mode == dm_auto)
6420 {
6421 GUI::ListData ac_types = GUI::ZCListData::autocombotypes();
6422 std::string type_name = ac_types.findText(combo_autos[combo_auto_pos].getType());
6423 if (is_compact)
6424 sprintf(comboprev_buf, "AC: %d CS: %d\n%s", combo_auto_pos, CSet, type_name.c_str());
6425 else
6426 sprintf(comboprev_buf, "Auto: %d CSet: %d\n%s\nEntries: %d", combo_auto_pos, CSet, type_name.c_str(), int32_t(combo_autos[combo_auto_pos].combos.size()));
6427 int x = combo_preview_text1.x + (combo_preview_text1.w * combo_preview_text1.xscale);
6428 textbox_out(menu1, txfont, x, combo_preview_text1.y, jwin_pal[jcBOXFG], jwin_pal[jcBOX], comboprev_buf, 2, &combo_preview_text1);
6429 }
6430 else if(draw_mode != dm_alias)
6431 {
6432 int x = combo_preview_text1.x+(combo_preview_text1.w*combo_preview_text1.xscale);
6433
6434 char shortbuf[512];
6435 char buf[256];
6436 strcpy(buf,combo_class_buf[combobuf[Combo].type].name);
6437 sprintf(comboprev_buf,"Combo: %d\nCSet: %d\n%s",Combo,CSet,buf);
6438 int ind = strlen(buf)-1;
6439 int x2 = x;
6440 if(x2 - text_length(txfont, buf) <= combolist_window.x)
6441 {
6442 auto dotlen = text_length(txfont, "..");
6443 x2 -= dotlen;
6444 while(x2 - text_length(txfont, buf) <= combolist_window.x)
6445 {
6446 if(ind < 0) break;
6447 buf[ind--] = '\0';
6448 }
6449 while(ind >= 0 && buf[ind] == ' ')
6450 buf[ind--] = 0; //trim spaces
6451 strcat(buf, "..");
6452 }
6453
6454 if(is_compact)
6455 {
6456 char b2[256];
6457 sprintf(b2, "Combo %d CS %d", Combo, CSet);
6458 if(x-text_length(txfont, b2) <= combolist_window.x)
6459 sprintf(b2, "Cmb %d CS %d", Combo, CSet);
6460 sprintf(shortbuf,"%s\n%s",b2,buf);
6461 }
6462 else sprintf(shortbuf,"Combo: %d\nCSet: %d\n%s",Combo,CSet,buf);
6463 textbox_out(menu1,txfont,x,combo_preview_text1.y,jwin_pal[jcBOXFG],jwin_pal[jcBOX],shortbuf,2,&combo_preview_text1);
6464 }
6465
6466 // Cycle
6467 if(!is_compact)
6468 {
6469 int32_t NextCombo = combobuf[Combo].nextcombo;
6470 int32_t NextCSet = combobuf[Combo].nextcset;
6471 if(combobuf[Combo].animflags & AF_CYCLEUNDERCOMBO)
6472 {
6473 mapscr* scr = Map.CurrScr();
6474 NextCombo = scr->undercombo;
6475 NextCSet = scr->undercset;
6476 }
6477 if(combobuf[Combo].animflags & AF_CYCLENOCSET)
6478 NextCSet = CSet;
6479 bool normal_dm = draw_mode != dm_alias && draw_mode != dm_cpool && draw_mode != dm_auto;
6480 jwin_draw_frame(menu1,combo_preview2.x-2,combo_preview2.y-2,combo_preview2.w+4,combo_preview2.h+4, FR_DEEP);
6481 if(NextCombo>0 && normal_dm)
6482 {
6483 put_combo(cycle_preview_bmp,0,0,NextCombo,NextCSet,Flags&(cFLAGS|cWALK),0);
6484
6485 if(Flags&cWALK) put_walkflags(cycle_preview_bmp,0,0,NextCombo,0);
6486
6487 if(Flags&cFLAGS) put_flags(cycle_preview_bmp,0,0,NextCombo,0,cFLAGS,0);
6488
6489 stretch_blit(cycle_preview_bmp, menu1, 0, 0, 16, 16, combo_preview2.x, combo_preview2.y, combo_preview2.w, combo_preview2.h);
6490 }
6491 else
6492 {
6493 if (InvalidBG == 2)
6494 {
6495 draw_checkerboard(menu1, combo_preview2.x, combo_preview2.y, 32);
6496 }
6497 else if(InvalidBG == 1)
6498 {
6499 for(int32_t dy=0; dy<combo_preview2.w; dy++)
6500 {
6501 for(int32_t dx=0; dx<combo_preview2.w; dx++)
6502 {
6503 menu1->line[dy+combo_preview2.y][dx+combo_preview2.x]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
6504 }
6505 }
6506 }
6507 else
6508 {
6509 rectfill(menu1, combo_preview2.x,combo_preview2.y, combo_preview2.x+32,combo_preview2.y+combo_preview2.h,vc(0));
6510 safe_rect(menu1, combo_preview2.x,combo_preview2.y, combo_preview2.x+32,combo_preview2.y+combo_preview2.h,vc(15));
6511 line(menu1, combo_preview2.x,combo_preview2.y, combo_preview2.x+32,combo_preview2.y+combo_preview2.h,vc(15));
6512 line(menu1, combo_preview2.x,combo_preview2.y+combo_preview2.h, combo_preview2.x+32,combo_preview2.y,vc(15));
6513 }
6514 }
6515
6516 if(normal_dm)
6517 {
6518 char shortbuf[512];
6519 char buf[256];
6520 strcpy(buf,combo_class_buf[combobuf[NextCombo].type].name);
6521 sprintf(comboprev_buf2, "Cycle: %d\nCSet: %d\n%s", NextCombo, NextCSet, buf);
6522 int ind = strlen(buf)-1;
6523 int x2 = combo_preview_text2.x;
6524 if(x2 + text_length(txfont, buf) > zq_screen_w-2)
6525 {
6526 auto dotlen = text_length(txfont, "..");
6527 x2 += dotlen;
6528 while(x2 + text_length(txfont, buf) > zq_screen_w-2)
6529 {
6530 if(ind < 0) break;
6531 buf[ind--] = '\0';
6532 }
6533 while(ind >= 0 && buf[ind] == ' ')
6534 buf[ind--] = 0; //trim spaces
6535 strcat(buf, "..");
6536 }
6537
6538 sprintf(shortbuf, "Cycle: %d\nCSet: %d\n%s", NextCombo, NextCSet, buf);
6539 textbox_out(menu1,txfont,combo_preview_text2.x,combo_preview_text2.y,jwin_pal[jcBOXFG],jwin_pal[jcBOX],shortbuf,0,&combo_preview_text2);
6540 }
6541 }
6542
6543 font = get_zc_font(font_lfont_l);
6544 bool merged = is_compact ? compact_merged_combopane : large_merged_combopane;
6545 draw_text_button(menu1,combo_merge_btn.x,combo_merge_btn.y,combo_merge_btn.w,combo_merge_btn.h,merged ? "<|>" : ">|<",vc(1),vc(14),0,true);
6546 }
6547 break;
6548 case rFAVORITES:
6549 {
6550 font = get_zc_font(font_lfont_l);
6551
6552 jwin_draw_frame(menu1,favorites_window.x,favorites_window.y,favorites_window.w,favorites_window.h, FR_WIN);
6553 rectfill(menu1,favorites_window.x+2,favorites_window.y+2,favorites_window.x+favorites_window.w-3,favorites_window.y+favorites_window.h-3,jwin_pal[jcBOX]);
6554 jwin_draw_frame(menu1,favorites_list.x-2,favorites_list.y-2,(favorites_list.w*favorites_list.xscale)+4,(favorites_list.h*favorites_list.yscale)+4, FR_DEEP);
6555 rectfill(menu1,favorites_list.x,favorites_list.y,favorites_list.x+(favorites_list.w*favorites_list.xscale)-1,favorites_list.y+(favorites_list.h*favorites_list.yscale)-1,jwin_pal[jcBOXFG]);
6556
6557 textprintf_ex(menu1,get_zc_font(font_lfont_l),favorites_list.x-2,favorites_list.y-15,jwin_pal[jcBOXFG],-1,is_compact ? "Favorites" : "Favorite Combos");
6558 BITMAP* subb = create_bitmap_ex(8,16,16);
6559
6560 for(int32_t col=0; col<favorites_list.w; ++col)
6561 {
6562 for(int32_t row=0; row<favorites_list.h; ++row)
6563 {
6564 auto i = (row*FAVORITECOMBO_PER_ROW)+col+FAVORITECOMBO_PER_PAGE*FavoriteComboPage;
6565 auto& sqr = favorites_list.subsquare(col,row);
6566 if(i >= MAXFAVORITECOMBOS || favorite_combos[i]==-1)
6567 {
6568 if (InvalidBG == 2)
6569 {
6570 draw_checkerboard(menu1, sqr.x, sqr.y, sqr.w);
6571 }
6572 else if(InvalidBG == 1)
6573 {
6574 for(int32_t dy=0; dy<sqr.h; dy++)
6575 {
6576 for(int32_t dx=0; dx<sqr.w; dx++)
6577 {
6578 menu1->line[sqr.y+dy][sqr.x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
6579 }
6580 }
6581 }
6582 else
6583 {
6584 xout(menu1, sqr.x, sqr.y, sqr.x+sqr.w-1, sqr.y+sqr.h-1, vc(15), vc(0));
6585 }
6586 }
6587 else
6588 {
6589 clear_bitmap(subb);
6590 bool repos = combotile_override_x < 0 && combotile_override_y < 0;
6591
6592 switch(favorite_combo_modes[i])
6593 {
6594 case dm_alias:
6595 draw_combo_alias_thumbnail(subb, &combo_aliases[favorite_combos[i]], 0, 0, 1);
6596 if (ShowFavoriteComboModes)
6597 put_engraving(subb, 0, 0, 0x3E, 1);
6598 break;
6599 case dm_cpool:
6600 {
6601 int32_t cid = -1; int8_t cs = CSet;
6602 combo_pool const& cp = combo_pools[favorite_combos[i]];
6603
6604 if (cp.get_w(cid, cs, 0) && !combobuf[cid].tile)
6605 cid = -1; //no tile to draw
6606 put_combo(subb, 0, 0, cid, cs, 0, 0);
6607 if (ShowFavoriteComboModes)
6608 put_engraving(subb, 0, 0, 0x3D, 1);
6609 break;
6610 }
6611 case dm_auto:
6612 {
6613 int32_t cid = -1; int8_t cs = CSet;
6614 combo_auto const& ca = combo_autos[favorite_combos[i]];
6615
6616 cid = ca.getDisplay();
6617 if (cid == 0)
6618 cid = -1;
6619 put_combo(subb, 0, 0, cid, cs, 0, 0);
6620 if (ShowFavoriteComboModes)
6621 put_engraving(subb, 0, 0, 0x3C, 1);
6622 break;
6623 }
6624 default:
6625 if (repos)
6626 {
6627 combotile_override_x = sqr.x + (sqr.w - 16) / 2;
6628 combotile_override_y = sqr.y + (sqr.h - 16) / 2;
6629 }
6630 put_combo(subb, 0, 0, favorite_combos[i], CSet, Flags & (cFLAGS | cWALK), 0);
6631 if (repos) combotile_override_x = combotile_override_y = -1;
6632 }
6633 stretch_blit(subb, menu1, 0, 0, 16, 16, sqr.x, sqr.y, sqr.w, sqr.h);
6634 }
6635 }
6636 }
6637
6638 destroy_bitmap(subb);
6639
6640 bool zoomed = is_compact ? compact_zoomed_fav : large_zoomed_fav;
6641 if(!is_compact)
6642 textprintf_right_ex(menu1, get_zc_font(font_lfont_l), favorites_pgleft.x - 2, favorites_pgleft.y, jwin_pal[jcBOXFG], -1, "%d/9", FavoriteComboPage + 1);
6643
6644 draw_text_button(menu1, favorites_pgleft.x, favorites_pgleft.y, favorites_pgleft.w, favorites_pgleft.h, is_compact ? "<" : "<-", vc(1), vc(14), 0, true);
6645 draw_text_button(menu1, favorites_pgright.x, favorites_pgright.y, favorites_pgright.w, favorites_pgright.h, is_compact ? ">" : "->", vc(1), vc(14), 0, true);
6646 draw_text_button(menu1,favorites_zoombtn.x,favorites_zoombtn.y,favorites_zoombtn.w,favorites_zoombtn.h,zoomed ? "-" : "+",vc(1),vc(14),0,true);
6647 draw_text_button(menu1,favorites_x.x,favorites_x.y,favorites_x.w,favorites_x.h,"X",vc(1),vc(14),0,true);
6648 draw_text_button(menu1,favorites_infobtn.x,favorites_infobtn.y,favorites_infobtn.w,favorites_infobtn.h,"?",vc(1),vc(14),0,true);
6649 }
6650 break;
6651 case rCOMMANDS:
6652 {
6653 jwin_draw_frame(menu1,commands_window.x,commands_window.y,commands_window.w,commands_window.h, FR_WIN);
6654 rectfill(menu1,commands_window.x+2,commands_window.y+2,commands_window.x+commands_window.w-3,commands_window.y+commands_window.h-3,jwin_pal[jcBOX]);
6655 jwin_draw_frame(menu1,commands_list.x-2,commands_list.y-2,(commands_list.w*commands_list.xscale)+4,(commands_list.h*commands_list.yscale)+4, FR_DEEP);
6656 rectfill(menu1,commands_list.x,commands_list.y,commands_list.x+(commands_list.w*commands_list.xscale)-1,commands_list.y+(commands_list.h*commands_list.yscale)-1,jwin_pal[jcBOXFG]);
6657 font=get_custom_font(CFONT_FAVCMD);
6658
6659 for(int32_t cmd=0; cmd<(commands_list.w*commands_list.h); ++cmd)
6660 {
6661 uint hkey = favorite_commands[cmd];
6662 draw_layer_button(menu1,
6663 (cmd%commands_list.w)*commands_list.xscale+commands_list.x,
6664 (cmd/commands_list.w)*commands_list.yscale+commands_list.y,
6665 commands_list.xscale,
6666 commands_list.yscale,
6667 get_hotkey_name(hkey),
6668 (selected_hotkey(hkey)?D_SELECTED:0) | (disabled_hotkey(hkey)?D_DISABLED:0));
6669 }
6670
6671 font = get_zc_font(font_lfont_l);
6672 if(commands_txt.x > 0)
6673 {
6674 gui_textout_ln(menu1, get_zc_font(font_lfont_l), (ucc*)"Favorite Commands", commands_txt.x, commands_txt.y, jwin_pal[jcBOXFG], -1, 0);
6675 }
6676
6677 bool zoomed = is_compact ? compact_zoomed_cmd : large_zoomed_cmd;
6678 draw_text_button(menu1,commands_zoombtn.x,commands_zoombtn.y,commands_zoombtn.w,commands_zoombtn.h,zoomed ? "-" : "+",vc(1),vc(14),0,true);
6679 draw_text_button(menu1,commands_x.x,commands_x.y,commands_x.w,commands_x.h,"X",vc(1),vc(14),0,true);
6680 draw_text_button(menu1,commands_infobtn.x,commands_infobtn.y,commands_infobtn.w,commands_infobtn.h,"?",vc(1),vc(14),0,true);
6681 }
6682 break;
6683 }
6684 font = tfont;
6685 }
6686
6687 bool pause_refresh = true;
6688 bool is_refreshing = false;
6689 11 void refresh(int32_t flags, bool update)
6690 {
6691
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(pause_refresh) return;
6692 static bool refreshing = false;
6693
6694 int num_screens_to_draw = Map.getViewSize();
6695
6696 bool earlyret = refreshing;
6697 is_refreshing = refreshing = true;
6698 //^ These prevent recursive calls from updating the screen early
6699
6700 bool zoom_delay = (zoomed_minimap && flags != rSCRMAP);
6701 if(zoom_delay)
6702 flags &= ~rSCRMAP;
6703
6704 if(flags&rCLEAR)
6705 {
6706 //magic pink = 0xED
6707 //system black = vc(0)
6708 //Clear a4 menu
6709 clear_to_color(menu1,jwin_pal[jcBOX]);
6710
6711 //Clears should refresh everything!
6712 flags |= rALL;
6713 }
6714
6715 if(flags&rSCRMAP)
6716 draw_screenunit(rSCRMAP,flags);
6717
6718 if(flags&rMAP)
6719 draw_screenunit(rMAP,flags);
6720
6721 if((flags&rCOMBOS) || (draw_mode == dm_cpool && (flags&rFAVORITES)))
6722 draw_screenunit(rCOMBOS,flags);
6723
6724 if(flags&(rCOMBO|rCOMBOS))
6725 draw_screenunit(rCOMBO,flags);
6726
6727 if(flags&rMENU)
6728 drawpanel();
6729
6730 if(flags&rFAVORITES)
6731 draw_screenunit(rFAVORITES,flags);
6732
6733 if(flags&rCOMMANDS)
6734 draw_screenunit(rCOMMANDS,flags);
6735
6736 FONT* tfont = font;
6737 font = get_custom_font(CFONT_GUI);
6738 jwin_draw_frame(menu1,layer_panel.x,layer_panel.y,layer_panel.w,layer_panel.h,FR_DEEP);
6739 rectfill(menu1,layer_panel.x,layer_panel.y,layer_panel.x+layer_panel.w-1,layer_panel.y+layer_panel.h-1,jwin_pal[jcBOX]);
6740
6741 for(int32_t i=0; i<=6; ++i)
6742 {
6743 char tbuf[15];
6744
6745 if (i>0 && mapscreen_valid_layers[i - 1] && num_screens_to_draw == 1)
6746 {
6747 if(is_compact)
6748 sprintf(tbuf, "%s%d %d:%02X", (i==2 && Map.CurrScr()->flags7&fLAYER2BG) || (i==3 && Map.CurrScr()->flags7&fLAYER3BG) ? "-":"", i, Map.CurrScr()->layermap[i-1], Map.CurrScr()->layerscreen[i-1]);
6749 else sprintf(tbuf, "%s%d (%d:%02X)", (i==2 && Map.CurrScr()->flags7&fLAYER2BG) || (i==3 && Map.CurrScr()->flags7&fLAYER3BG) ? "-":"", i, Map.CurrScr()->layermap[i-1], Map.CurrScr()->layerscreen[i-1]);
6750 }
6751 else
6752 {
6753 sprintf(tbuf, "%s%d", (i==2 && Map.CurrScr()->flags7&fLAYER2BG) || (i==3 && Map.CurrScr()->flags7&fLAYER3BG) ? "-":"", i);
6754 }
6755
6756 int32_t spacing_offs = is_compact ? 2 : 10;
6757 int32_t rx = (i * (layerpanel_buttonwidth+spacing_offs+layerpanel_checkbox_wid)) + layer_panel.x+(is_compact?2:6);
6758 int32_t ry = layer_panel.y;
6759 auto cbyofs = (layerpanel_buttonheight-layerpanel_checkbox_hei)/2;
6760 draw_layer_button(menu1, rx, ry, layerpanel_buttonwidth, layerpanel_buttonheight, tbuf, CurrentLayer==i? D_SELECTED : ( i > 0 && !mapscreen_valid_layers[i-1]) ? D_DISABLED : 0);
6761 draw_checkbox(menu1,rx+layerpanel_buttonwidth+1,ry+cbyofs,layerpanel_checkbox_wid,layerpanel_checkbox_hei,LayerMaskInt[i]!=0);
6762 }
6763
6764 font=tfont;
6765
6766 // } //if(true)
6767 if(zq_showpal)
6768 {
6769 for(int32_t i=0; i<256; i++)
6770 {
6771 rectfill(menu1,((i&15)<<2)+256,((i>>4)<<2)+176,((i&15)<<2)+259,((i>>4)<<2)+179,i);
6772 }
6773 }
6774 { //Show top-left info
6775 size_t maxwid = (mapscreen_screenunit_scale*mapscreenbmp->w)-1;
6776 size_t maxhei = (mapscreen_screenunit_scale*mapscreenbmp->w);
6777 set_clip_rect(menu1,mapscreen_x,mapscreen_y,mapscreen_x+maxwid-1,mapscreen_y+maxhei-1);
6778 FONT* showfont = get_custom_font(CFONT_INFO);
6779 int showfont_h = text_height(showfont);
6780 int32_t ypos = mapscreen_y;
6781 if(prv_mode)
6782 {
6783 textout_shadowed_ex(menu1,showfont,"Preview Mode",0,ypos,vc(15),vc(0),infobg?vc(0):-1);
6784 ypos += showfont_h+1;
6785 if(prv_twon)
6786 {
6787 textprintf_shadowed_ex(menu1,showfont,0,ypos,vc(15),vc(0),infobg?vc(0):-1,"T Warp=%d tics", Map.get_prvtime());
6788 ypos += showfont_h+1;
6789 }
6790 }
6791 if(ShowFPS)
6792 {
6793 textprintf_shadowed_ex(menu1,showfont,0,ypos,vc(15),vc(0),infobg?vc(0):-1,"FPS: %3d",lastfps);
6794 ypos += showfont_h+1;
6795 }
6796
6797 if(ShowFFScripts && !prv_mode)
6798 {
6799 word num_ffcs = Map.CurrScr()->numFFC();
6800 for(word i=0; i< num_ffcs; i++)
6801 {
6802 if(ypos+showfont_h-1 > map_page_bar[0].y)
6803 break;
6804 if(Map.CurrScr()->ffcs[i].script && Map.CurrScr()->ffcs[i].data)
6805 {
6806 textout_shadowed_ex(menu1, showfont, ffcmap[Map.CurrScr()->ffcs[i].script-1].scriptname.substr(0,300).c_str(),0,ypos,vc(showxypos_ffc==i ? 14 : 15),vc(0),infobg?vc(0):-1);
6807 ypos+=showfont_h+1;
6808 }
6809 }
6810 }
6811 clear_clip_rect(menu1);
6812 if(prv_mode)
6813 do_previewtext();
6814 }
6815 // Show Errors & Details
6816 //This includes the presence of: Screen State Carryover, Timed Warp, Maze Path, the 'Sideview Gravity', 'Invisible Hero',
6817 //'Save Screen', 'Continue Here' and 'Treat As..' Screen Flags,
6818 // the String, every Room Type and Catch All, and all four Tile and Side Warps.
6819 if(!prv_mode && ShowInfo)
6820 {
6821 int32_t i=0;
6822 char buf[2048];
6823
6824 // Start with general information
6825 if(Map.CurrScr()->flags3&fINVISHERO)
6826 {
6827 sprintf(buf,"Invisible Hero");
6828 show_screen_error(buf,i++,vc(15));
6829 }
6830
6831 if(Map.getLayerTargetMap() > 0)
6832 {
6833 Map.setlayertarget(); //Now the text does not carry over when changing maps, but shifting back, it does not **re-appear** until you change screens.
6834 //It was also required to set some updates in onDecMap and onIncMap. #
6835 //This fixes Screen Info not displaying properly when changing maps. -Z
6836 //Needed to refresh the screen info. -Z ( 26th March, 2019 )
6837 int32_t m = Map.getLayerTargetMultiple();
6838 sprintf(buf,"Used as a layer by screen %d:%02X",Map.getLayerTargetMap(),Map.getLayerTargetScr());
6839 char buf2[24];
6840
6841 if(m>0)
6842 {
6843 sprintf(buf2," and %d other%s",m,m>1?"s":"");
6844 strcat(buf,buf2);
6845 }
6846
6847 show_screen_error(buf,i++,vc(15));
6848 }
6849
6850 if(Map.CurrScr()->nextmap)
6851 {
6852 sprintf(buf,"Screen State carries over to %d:%02X",Map.CurrScr()->nextmap,Map.CurrScr()->nextscr);
6853 show_screen_error(buf,i++,vc(15));
6854 }
6855
6856 if(Map.CurrScr()->timedwarptics)
6857 {
6858 sprintf(buf,"%s%sTimed Warp: %s",(Map.CurrScr()->flags4&fTIMEDDIRECT)?"Direct ":"",(Map.CurrScr()->flags5&fRANDOMTIMEDWARP)?"Random ":"",ticksstr(Map.CurrScr()->timedwarptics));
6859 show_screen_error(buf,i++,vc(15));
6860 }
6861
6862 if(Map.CurrScr()->flags&fMAZE)
6863 {
6864 sprintf(buf,"Maze Path: %s (Exit %s)",pathstr(Map.CurrScr()->path),mazedirstr[Map.CurrScr()->exitdir]);
6865 show_screen_error(buf,i++,vc(15));
6866 }
6867
6868 bool continuescreen = false, savecombo = false;
6869
6870 if(Map.CurrScr()->flags4&fAUTOSAVE)
6871 {
6872 sprintf(buf,"Automatic Save%s Screen", (Map.CurrScr()->flags6&fCONTINUEHERE) ? "-Continue":"");
6873 show_screen_error(buf,i++,vc(15));
6874 continuescreen = ((Map.CurrScr()->flags6&fCONTINUEHERE)!=0);
6875 savecombo = true;
6876 }
6877 else if(Map.CurrScr()->flags6&fCONTINUEHERE)
6878 {
6879 sprintf(buf,"Continue Screen");
6880 show_screen_error(buf,i++,vc(15));
6881 continuescreen = true;
6882 }
6883
6884 if(isSideViewGravity())
6885 {
6886 sprintf(buf,"Sideview Gravity");
6887 show_screen_error(buf,i++,vc(15));
6888 }
6889
6890 if(Map.CurrScr()->flags6 & (fCAVEROOM|fDUNGEONROOM))
6891 {
6892 sprintf(buf,"Treat As %s%s Screen", (Map.CurrScr()->flags6&fCAVEROOM) ? "Interior":"NES Dungeon",
6893 (Map.CurrScr()->flags6 & (fCAVEROOM|fDUNGEONROOM)) == (fCAVEROOM|fDUNGEONROOM) ? " or NES Dungeon":"");
6894 show_screen_error(buf,i++,vc(15));
6895 }
6896
6897 if(Map.CurrScr()->oceansfx != 0)
6898 {
6899 sprintf(buf,"Ambient Sound: %s",sfx_string[Map.CurrScr()->oceansfx]);
6900 show_screen_error(buf,i++,vc(15));
6901 }
6902
6903 if(Map.CurrScr()->bosssfx != 0)
6904 {
6905 sprintf(buf,"Boss Roar Sound: %s",sfx_string[Map.CurrScr()->bosssfx]);
6906 show_screen_error(buf,i++,vc(15));
6907 }
6908
6909 if(Map.CurrScr()->str)
6910 {
6911 strncpy(buf,MsgString(Map.CurrScr()->str, true, false),72);
6912 buf[72] = '\0';
6913 char shortbuf[72];
6914 strip_extra_spaces(buf);
6915 shorten_string(shortbuf, buf, get_zc_font(font_lfont_l), 72, 280);
6916 sprintf(buf,"String %s",shortbuf);
6917 show_screen_error(buf,i++,vc(15));
6918 }
6919
6920 if((Map.CurrScr()->flags&fWHISTLE) || (Map.CurrScr()->flags7&fWHISTLEWATER))
6921 {
6922 sprintf(buf,"Whistle ->%s%s%s",(Map.CurrScr()->flags&fWHISTLE)?" Stairs":"",
6923 (Map.CurrScr()->flags&fWHISTLE && Map.CurrScr()->flags7&fWHISTLEWATER)?", ":"",
6924 (Map.CurrScr()->flags7&fWHISTLEWATER)?"Dry Lake":"");
6925 show_screen_error(buf,i++,vc(15));
6926 }
6927
6928 switch(Map.CurrScr()->room)
6929 {
6930 case rSP_ITEM:
6931 sprintf(buf,"Special Item is %s",item_string[Map.CurrScr()->catchall]);
6932 show_screen_error(buf,i++, vc(15));
6933 break;
6934
6935 case rINFO:
6936 {
6937 int32_t shop = Map.CurrScr()->catchall;
6938 sprintf(buf,"Pay For Info: -%d, -%d, -%d",
6939 QMisc.info[shop].price[0],QMisc.info[shop].price[1],QMisc.info[shop].price[2]);
6940 show_screen_error(buf,i++, vc(15));
6941 }
6942 break;
6943
6944 case rMONEY:
6945 sprintf(buf,"Secret Money: %d Rupees",Map.CurrScr()->catchall);
6946 show_screen_error(buf,i++, vc(15));
6947 break;
6948
6949 case rGAMBLE:
6950 show_screen_error("Gamble Room",i++, vc(15));
6951 break;
6952
6953 case rREPAIR:
6954 sprintf(buf,"Door Repair: -%d Rupees",Map.CurrScr()->catchall);
6955 show_screen_error(buf,i++, vc(15));
6956 break;
6957
6958 case rRP_HC:
6959 sprintf(buf,"Take %s or %s", item_string[iRPotion], item_string[iHeartC]);
6960 show_screen_error(buf,i++, vc(15));
6961 break;
6962
6963 case rGRUMBLE:
6964 show_screen_error("Feed the Goriya",i++, vc(15));
6965 break;
6966
6967 case rTRIFORCE:
6968 show_screen_error("Triforce Check",i++, vc(15));
6969 break;
6970
6971 case rP_SHOP:
6972 case rSHOP:
6973 {
6974 int32_t shop = Map.CurrScr()->catchall;
6975 sprintf(buf,"%sShop: ",
6976 Map.CurrScr()->room==rP_SHOP ? "Potion ":"");
6977
6978 for(int32_t j=0; j<3; j++) if(QMisc.shop[shop].item[j]>0) // Print the 3 items and prices
6979 {
6980 strcat(buf,item_string[QMisc.shop[shop].item[j]]);
6981 strcat(buf,":");
6982 char pricebuf[8];
6983 sprintf(pricebuf,"%d",QMisc.shop[shop].price[j]);
6984 strcat(buf,pricebuf);
6985
6986 if(j<2 && QMisc.shop[shop].item[j+1]>0) strcat(buf,", ");
6987 }
6988
6989 show_screen_error(buf,i++, vc(15));
6990 }
6991 break;
6992
6993 case rBOTTLESHOP:
6994 {
6995 int32_t shop = Map.CurrScr()->catchall;
6996 sprintf(buf,"Bottle Shop: ");
6997
6998 for(int32_t j=0; j<3; j++) if(QMisc.bottle_shop_types[shop].fill[j]>0) // Print the 3 fills and prices
6999 {
7000 strcat(buf,QMisc.bottle_types[QMisc.bottle_shop_types[shop].fill[j]-1].name);
7001 strcat(buf,":");
7002 char pricebuf[8];
7003 sprintf(pricebuf,"%d",QMisc.bottle_shop_types[shop].price[j]);
7004 strcat(buf,pricebuf);
7005
7006 if(j<2 && QMisc.bottle_shop_types[shop].fill[j+1]>0) strcat(buf,", ");
7007 }
7008
7009 show_screen_error(buf,i++, vc(15));
7010 }
7011 break;
7012
7013 case rTAKEONE:
7014 {
7015 int32_t shop = Map.CurrScr()->catchall;
7016 sprintf(buf,"Take Only One: %s%s%s%s%s",
7017 QMisc.shop[shop].item[0]<1?"":item_string[QMisc.shop[shop].item[0]],QMisc.shop[shop].item[0]>0?", ":"",
7018 QMisc.shop[shop].item[1]<1?"":item_string[QMisc.shop[shop].item[1]],(QMisc.shop[shop].item[1]>0&&QMisc.shop[shop].item[2]>0)?", ":"",
7019 QMisc.shop[shop].item[2]<1?"":item_string[QMisc.shop[shop].item[2]]);
7020 show_screen_error(buf,i++, vc(15));
7021 }
7022 break;
7023
7024 case rBOMBS:
7025 sprintf(buf,"More Bombs: -%d Rupees",Map.CurrScr()->catchall);
7026 show_screen_error(buf,i++, vc(15));
7027 break;
7028
7029 case rARROWS:
7030 sprintf(buf,"More Arrows: -%d Rupees",Map.CurrScr()->catchall);
7031 show_screen_error(buf,i++, vc(15));
7032 break;
7033
7034 case rSWINDLE:
7035 sprintf(buf,"Leave Life or %d Rupees",Map.CurrScr()->catchall);
7036 show_screen_error(buf,i++, vc(15));
7037 break;
7038
7039 case r10RUPIES:
7040 show_screen_error("10 Rupees",i++, vc(15));
7041 break;
7042
7043 case rGANON:
7044 show_screen_error("Ganon Room",i++, vc(15));
7045 break;
7046
7047 case rZELDA:
7048 show_screen_error("Zelda Room",i++, vc(15));
7049 break;
7050
7051 case rMUPGRADE:
7052 show_screen_error("1/2 Magic Upgrade",i++, vc(15));
7053 break;
7054
7055 case rLEARNSLASH:
7056 show_screen_error("Learn Slash",i++, vc(15));
7057 break;
7058
7059 case rWARP:
7060 sprintf(buf,"3-Stair Warp: Warp Ring %d",Map.CurrScr()->catchall);
7061 show_screen_error(buf,i++, vc(15));
7062 break;
7063 }
7064
7065 bool undercombo = false, warpa = false, warpb = false, warpc = false, warpd = false, warpr = false;
7066
7067 word num_ffcs = Map.CurrScr()->numFFC();
7068 for(int32_t c=0; c<176+128+1+num_ffcs; ++c)
7069 {
7070 // Checks both combos, secret combos, undercombos and FFCs
7071 //Fixme:
7072 int32_t ctype =
7073 combobuf[vbound(
7074 (c>=305 ? Map.CurrScr()->ffcs[c-305].data :
7075 c>=304 ? Map.CurrScr()->undercombo :
7076 c>=176 ? Map.CurrScr()->secretcombo[c-176] :
7077 !Map.CurrScr()->valid ? 0 : // Sanity check: does room combo data exist?
7078 Map.CurrScr()->data[c]
7079 ), 0, MAXCOMBOS-1)].type;
7080
7081 if(!undercombo && integrityBoolUnderCombo(Map.CurrScr(),ctype))
7082 {
7083 undercombo = true;
7084 show_screen_error("Under Combo is combo 0",i++, vc(7));
7085 }
7086
7087 // Tile Warp types
7088 switch(ctype)
7089 {
7090 case cSAVE:
7091 case cSAVE2:
7092 if(!savecombo)
7093 {
7094 savecombo = true;
7095
7096 if(integrityBoolSaveCombo(Map.CurrScr(),ctype))
7097 show_screen_error("Save Screen",i++, vc(15));
7098 else
7099 show_screen_error("Save-Continue Screen",i++, vc(15));
7100 }
7101
7102 break;
7103
7104 case cSTAIRR:
7105 case cPITR:
7106 case cSWARPR:
7107 if(!warpr && (Map.CurrScr()->tilewarptype[0]==wtCAVE || Map.CurrScr()->tilewarptype[1]==wtCAVE ||
7108 Map.CurrScr()->tilewarptype[2]==wtCAVE || Map.CurrScr()->tilewarptype[3]==wtCAVE))
7109 {
7110 warpr = true;
7111 show_screen_error("Random Tile Warp contains Cave/Item Cellar",i++, vc(7));
7112 }
7113
7114 break;
7115
7116 case cCAVED:
7117 case cPITD:
7118 case cSTAIRD:
7119 case cCAVE2D:
7120 case cSWIMWARPD:
7121 case cDIVEWARPD:
7122 case cSWARPD:
7123 if(!warpd)
7124 {
7125 warpd = true;
7126 tile_warp_notification(3,buf);
7127 show_screen_error(buf,i++, vc(15));
7128 }
7129
7130 break;
7131
7132 case cCAVEC:
7133 case cPITC:
7134 case cSTAIRC:
7135 case cCAVE2C:
7136 case cSWIMWARPC:
7137 case cDIVEWARPC:
7138 case cSWARPC:
7139 if(!warpc)
7140 {
7141 warpc = true;
7142 tile_warp_notification(2,buf);
7143 show_screen_error(buf,i++, vc(15));
7144 }
7145
7146 break;
7147
7148 case cCAVEB:
7149 case cPITB:
7150 case cSTAIRB:
7151 case cCAVE2B:
7152 case cSWIMWARPB:
7153 case cDIVEWARPB:
7154 case cSWARPB:
7155 if(!warpb)
7156 {
7157 warpb = true;
7158 tile_warp_notification(1,buf);
7159 show_screen_error(buf,i++, vc(15));
7160 }
7161
7162 break;
7163
7164 case cCAVE:
7165 case cPIT:
7166 case cSTAIR:
7167 case cCAVE2:
7168 case cSWIMWARP:
7169 case cDIVEWARP:
7170 case cSWARPA:
7171 if(!warpa)
7172 {
7173 warpa = true;
7174 tile_warp_notification(0,buf);
7175 show_screen_error(buf,i++, vc(15));
7176 }
7177
7178 break;
7179 }
7180 }
7181
7182 int32_t sidewarpnotify = 0;
7183
7184 if(Map.CurrScr()->flags2&wfUP)
7185 {
7186 side_warp_notification(Map.CurrScr()->sidewarpindex&3,0,buf);
7187 show_screen_error(buf,i++, vc(15));
7188 sidewarpnotify|=(1<<(Map.CurrScr()->sidewarpindex&3));
7189 }
7190
7191 if(Map.CurrScr()->flags2&wfDOWN)
7192 {
7193 side_warp_notification((Map.CurrScr()->sidewarpindex>>2)&3,1,buf);
7194 show_screen_error(buf,i++, vc(15));
7195 sidewarpnotify|=(1<<((Map.CurrScr()->sidewarpindex>>2)&3));
7196 }
7197
7198 if(Map.CurrScr()->flags2&wfLEFT)
7199 {
7200 side_warp_notification((Map.CurrScr()->sidewarpindex>>4)&3,2,buf);
7201 show_screen_error(buf,i++, vc(15));
7202 sidewarpnotify|=(1<<((Map.CurrScr()->sidewarpindex>>4)&3));
7203 }
7204
7205 if(Map.CurrScr()->flags2&wfRIGHT)
7206 {
7207 side_warp_notification((Map.CurrScr()->sidewarpindex>>6)&3,3,buf);
7208 show_screen_error(buf,i++, vc(15));
7209 sidewarpnotify|=(1<<((Map.CurrScr()->sidewarpindex>>6)&3));
7210 }
7211
7212 if(!(sidewarpnotify&1) && Map.CurrScr()->timedwarptics)
7213 {
7214 side_warp_notification(0,4,buf); // Timed Warp
7215 show_screen_error(buf,i++, vc(15));
7216 }
7217
7218 // Now for errors
7219 if((Map.CurrScr()->flags4&fSAVEROOM) && !savecombo) show_screen_error("Save Point->Continue Here, but no Save Point combo?",i++, vc(14));
7220
7221 if(integrityBoolEnemiesItem(Map.CurrScr())) show_screen_error("Enemies->Item, but no enemies",i++, vc(7));
7222
7223 if(integrityBoolEnemiesSecret(Map.CurrScr())) show_screen_error("Enemies->Secret, but no enemies",i++, vc(7));
7224
7225 if(integrityBoolGuyNoString(Map.CurrScr())) show_screen_error("Non-Fairy Guy, but String is (none)",i++, vc(14));
7226
7227 if(integrityBoolRoomNoGuy(Map.CurrScr())) show_screen_error("Guy is (none)",i++, vc(14));
7228
7229 if(integrityBoolRoomNoString(Map.CurrScr())) show_screen_error("String is (none)",i++, vc(14));
7230
7231 if(integrityBoolRoomNoGuyNoString(Map.CurrScr())) show_screen_error("Guy and String are (none)",i++, vc(14));
7232 }
7233
7234 if(zoom_delay)
7235 draw_screenunit(rSCRMAP,flags);
7236
7237
7238 if(flags&rCLEAR)
7239 {
7240 //Draw the whole gui
7241 blit(menu1,screen,0,0,0,0,zq_screen_w,zq_screen_h);
7242 }
7243 else
7244 {
7245 blit(menu1,screen,0,16,0,16,zq_screen_w,zq_screen_h-16);
7246 blit(menu1,screen,combolist_window.x-64,0,combolist_window.x-64,0,combolist_window.w+64,16);
7247
7248 if(flags&rCOMBO)
7249 blit(menu1,screen,combo_preview.x,combo_preview.y,combo_preview.x,combo_preview.y,combo_preview.w,combo_preview.h);
7250 }
7251
7252 if(earlyret)
7253 return;
7254
7255 //Draw the Main Menu
7256 rectfill(screen,mainbar.x,mainbar.y,mainbar.x+mainbar.w-1,mainbar.y+mainbar.h-1,jwin_pal[jcBOX]);
7257 jwin_draw_frame(screen,mainbar.x,mainbar.y,mainbar.w,mainbar.h,FR_WIN);
7258
7259 FONT* oldfont = font;
7260 font = get_custom_font(CFONT_GUI);
7261
7262 //Drawmode button
7263 draw_text_button(screen,drawmode_btn.x,drawmode_btn.y,drawmode_btn.w,drawmode_btn.h,dm_names[draw_mode],vc(1),vc(14),0,true);
7264 //Compact button
7265 draw_text_button(screen,compactbtn.x, compactbtn.y, compactbtn.w, compactbtn.h, is_compact ? "< Expand" : "> Compact", vc(1),vc(14),0,true);
7266 //Zoom buttons
7267 zoom_in_btn_disabled = num_screens_to_draw == 1;
7268 zoom_out_btn_disabled = num_screens_to_draw == mapscreen_num_screens_to_draw_max;
7269 draw_text_button(screen,zoominbtn.x, zoominbtn.y, zoominbtn.w, zoominbtn.h, "+", vc(1),vc(14),zoom_in_btn_disabled ? D_DISABLED : 0,true);
7270 draw_text_button(screen,zoomoutbtn.x, zoomoutbtn.y, zoomoutbtn.w, zoomoutbtn.h, "-", vc(1),vc(14),zoom_out_btn_disabled ? D_DISABLED : 0,true);
7271
7272 font = oldfont;
7273
7274 d_nbmenu_proc(MSG_DRAW, &dialogs[0], 0);
7275
7276 ComboBrushPause=0;
7277
7278 SCRFIX();
7279 if(update)
7280 custom_vsync();
7281 is_refreshing = refreshing = false;
7282 11 }
7283
7284 12 static int minimap_tooltip_id = ttip_register_id();
7285
7286 void select_scr()
7287 {
7288 if(Map.getCurrMap()>=Map.getMapCount())
7289 return;
7290
7291 int32_t tempcb=ComboBrush;
7292 ComboBrush=0;
7293
7294 size_and_pos const& real_mini = zoomed_minimap ? real_minimap_zoomed : real_minimap;
7295
7296 //scooby
7297 while(gui_mouse_b())
7298 {
7299 int32_t x=gui_mouse_x();
7300 int32_t y=gui_mouse_y();
7301
7302 int32_t ind = real_mini.rectind(x,y);
7303
7304 if(ind>=MAPSCRS)
7305 ind-=16;
7306
7307 if(ind > -1 && ind != Map.getCurrScr())
7308 {
7309 Map.setCurrScr(ind);
7310 }
7311
7312 custom_vsync();
7313 refresh(rALL);
7314 }
7315
7316 ComboBrush=tempcb;
7317 }
7318
7319 void clear_cpool()
7320 {
7321 for(int32_t i=0; i<MAXFAVORITECOMBOS; ++i)
7322 {
7323 pool_combos[i].clear();
7324 }
7325 pool_dirty = true;
7326 }
7327
7328 bool select_favorite()
7329 {
7330 int32_t tempcb=ComboBrush;
7331 ComboBrush=0;
7332 bool valid=false;
7333
7334 while(gui_mouse_b())
7335 {
7336 valid=false;
7337 int32_t x=gui_mouse_x();
7338
7339 if(x<favorites_list.x)
7340 x=favorites_list.x;
7341
7342 if(x>favorites_list.x+(favorites_list.w*favorites_list.xscale)-1)
7343 x=favorites_list.x+(favorites_list.w*favorites_list.xscale)-1;
7344
7345 int32_t y=gui_mouse_y();
7346
7347 if(y<favorites_list.y)
7348 y=favorites_list.y;
7349
7350 if(y>favorites_list.y+(favorites_list.h*favorites_list.yscale)-1)
7351 y=favorites_list.y+(favorites_list.h*favorites_list.yscale)-1;
7352
7353 int32_t tempc=(((y-favorites_list.y)/favorites_list.yscale)*FAVORITECOMBO_PER_ROW)+((x-favorites_list.x)/favorites_list.xscale) + FAVORITECOMBO_PER_PAGE * FavoriteComboPage;
7354
7355 if(tempc >= MAXFAVORITECOMBOS)
7356 {
7357 //Nothing, invalid
7358 }
7359 else
7360 {
7361 if(favorite_combos[tempc]!=-1)
7362 {
7363 switch(favorite_combo_modes[tempc])
7364 {
7365 case dm_alias:
7366 draw_mode = dm_alias;
7367 combo_apos = favorite_combos[tempc];
7368 break;
7369 case dm_cpool:
7370 draw_mode = dm_cpool;
7371 combo_pool_pos = favorite_combos[tempc];
7372 break;
7373 case dm_auto:
7374 draw_mode = dm_auto;
7375 combo_auto_pos = favorite_combos[tempc];
7376 break;
7377 default:
7378 draw_mode = dm_normal;
7379 Combo = favorite_combos[tempc];
7380 }
7381 if(AutoBrush)
7382 BrushWidth = BrushHeight = 1;
7383 valid=true;
7384 fix_drawing_mode_menu();
7385 }
7386 }
7387
7388 custom_vsync();
7389 refresh(rALL);
7390 }
7391
7392 ComboBrush=tempcb;
7393 return valid;
7394 }
7395
7396 void select_combo(int32_t clist)
7397 {
7398 current_combolist=clist;
7399 int32_t tempcb=ComboBrush;
7400 ComboBrush=0;
7401
7402 int autobrush_cx = -1, autobrush_cy = -1;
7403 int autobrush_first = First[current_combolist];
7404 auto& curlist = combolist[current_combolist];
7405 AutoBrushRevert = (key[KEY_ALT]||key[KEY_ALTGR]);
7406 while(gui_mouse_b())
7407 {
7408 int32_t x=gui_mouse_x();
7409
7410 if(x<curlist.x)
7411 x=curlist.x;
7412
7413 if(x>curlist.x+(curlist.w*curlist.xscale)-1)
7414 x=curlist.x+(curlist.w*curlist.xscale)-1;
7415
7416 int32_t y=gui_mouse_y();
7417
7418 if(y<curlist.y)
7419 y=curlist.y;
7420
7421 if(y>curlist.y+(curlist.h*curlist.yscale)-1)
7422 y=curlist.y+(curlist.h*curlist.yscale)-1;
7423
7424 int cx = ((x-curlist.x)/curlist.xscale), cy = ((y-curlist.y)/curlist.yscale);
7425 if(AutoBrush)
7426 {
7427 if(autobrush_cx < 0)
7428 {
7429 autobrush_cx = cx;
7430 autobrush_cy = cy;
7431 }
7432 BrushWidth = vbound(abs(autobrush_cx-cx)+1,1,16);
7433 BrushHeight = vbound(abs(autobrush_cy-cy)+1,1,11);
7434 cx = std::min(autobrush_cx,cx);
7435 cy = std::min(autobrush_cy,cy);
7436 }
7437 Combo=(cy*curlist.w)+cx+First[current_combolist];
7438 custom_vsync();
7439 refresh(rALL);
7440 if(AutoBrush) //Prevent any scrolling
7441 First[current_combolist] = autobrush_first;
7442 }
7443 if(key[KEY_ALT]||key[KEY_ALTGR])
7444 AutoBrushRevert = true;
7445 position_mouse_z(0);
7446 ComboBrush=tempcb;
7447 }
7448
7449 void select_comboa(int32_t clist)
7450 {
7451 current_comboalist=clist;
7452 int32_t tempcb=ComboBrush;
7453 ComboBrush=0;
7454 alias_cset_mod=0;
7455
7456 auto& curlist = comboaliaslist[current_comboalist];
7457 while(gui_mouse_b())
7458 {
7459 int32_t x=gui_mouse_x();
7460
7461 if(x<curlist.x)
7462 x=curlist.x;
7463
7464 if(x>curlist.x+(curlist.w*curlist.xscale)-1)
7465 x=curlist.x+(curlist.w*curlist.xscale)-1;
7466
7467 int32_t y=gui_mouse_y();
7468
7469 if(y<curlist.y)
7470 y=curlist.y;
7471
7472 if(y>curlist.y+(curlist.h*curlist.yscale)-1)
7473 y=curlist.y+(curlist.h*curlist.yscale)-1;
7474
7475 combo_apos=(((y-curlist.y)/curlist.yscale)*curlist.w)+((x-curlist.x)/curlist.xscale)+combo_alistpos[current_comboalist];
7476 custom_vsync();
7477 refresh(rALL);
7478 }
7479
7480 ComboBrush=tempcb;
7481 }
7482
7483 void select_combop(int32_t clist)
7484 {
7485 current_cpoollist=clist;
7486 int32_t tempcb=ComboBrush;
7487 ComboBrush=0;
7488
7489 auto& curlist = comboaliaslist[current_cpoollist];
7490 while(gui_mouse_b())
7491 {
7492 int32_t x=gui_mouse_x();
7493
7494 if(x<curlist.x) x=curlist.x;
7495
7496 if(x>curlist.x+(curlist.w*curlist.xscale)-1)
7497 x=curlist.x+(curlist.w*curlist.xscale)-1;
7498
7499 int32_t y=gui_mouse_y();
7500
7501 if(y<curlist.y) y=curlist.y;
7502
7503 if(y>curlist.y+(curlist.h*curlist.yscale)-1)
7504 y=curlist.y+(curlist.h*curlist.yscale)-1;
7505
7506 combo_pool_pos=(((y-curlist.y)/curlist.yscale)*curlist.w)+((x-curlist.x)/curlist.xscale)+combo_pool_listpos[current_cpoollist];
7507 custom_vsync();
7508 refresh(rALL);
7509 }
7510
7511 ComboBrush=tempcb;
7512 }
7513
7514 void select_autocombo(int32_t clist)
7515 {
7516 current_cautolist = clist;
7517 int32_t tempcb = ComboBrush;
7518 ComboBrush = 0;
7519
7520 auto& curlist = comboaliaslist[current_cautolist];
7521 while (gui_mouse_b())
7522 {
7523 int32_t x = gui_mouse_x();
7524
7525 if (x < curlist.x) x = curlist.x;
7526
7527 if (x > curlist.x + (curlist.w * curlist.xscale) - 1)
7528 x = curlist.x + (curlist.w * curlist.xscale) - 1;
7529
7530 int32_t y = gui_mouse_y();
7531
7532 if (y < curlist.y) y = curlist.y;
7533
7534 if (y > curlist.y + (curlist.h * curlist.yscale) - 1)
7535 y = curlist.y + (curlist.h * curlist.yscale) - 1;
7536
7537 combo_auto_pos = (((y - curlist.y) / curlist.yscale) * curlist.w) + ((x - curlist.x) / curlist.xscale) + combo_auto_listpos[current_cautolist];
7538 cauto_height = combo_autos[combo_auto_pos].getArg() + 1;
7539 custom_vsync();
7540 refresh(rALL);
7541 }
7542
7543 ComboBrush = tempcb;
7544 }
7545
7546 void update_combobrush()
7547 {
7548 clear_bitmap(brushbmp);
7549
7550 if(draw_mode==dm_alias)
7551 {
7552 //int32_t count=(combo_aliases[combo_apos].width+1)*(combo_aliases[combo_apos].height+1)*(comboa_lmasktotal(combo_aliases[combo_apos].layermask));
7553 for(int32_t z=0; z<=comboa_lmasktotal(combo_aliases[combo_apos].layermask); z++)
7554 {
7555 for(int32_t y=0; y<=combo_aliases[combo_apos].height; y++)
7556 {
7557 for(int32_t x=0; x<=combo_aliases[combo_apos].width; x++)
7558 {
7559 int32_t position = ((y*(combo_aliases[combo_apos].width+1))+x)+((combo_aliases[combo_apos].width+1)*(combo_aliases[combo_apos].height+1)*z);
7560
7561 if(combo_aliases[combo_apos].combos[position])
7562 {
7563 if(z==0)
7564 {
7565 putcombo(brushbmp,x<<4,y<<4,combo_aliases[combo_apos].combos[position],wrap(combo_aliases[combo_apos].csets[position]+alias_cset_mod, 0, 13));
7566 }
7567 else
7568 {
7569 overcombo(brushbmp,x<<4,y<<4,combo_aliases[combo_apos].combos[position],wrap(combo_aliases[combo_apos].csets[position]+alias_cset_mod, 0, 13));
7570 }
7571 }
7572 }
7573 }
7574 }
7575
7576 int xoff = 6, yoff = 6;
7577 if(FloatBrush) // Offset the floating pixels, so the 'x' appears centered on the combo still -Em
7578 {
7579 xoff += 2;
7580 yoff += 2;
7581 }
7582 if(alias_origin & 1) // Right-align
7583 xoff += combo_aliases[combo_apos].width*16;
7584 if(alias_origin & 2) // Bottom-align
7585 yoff += combo_aliases[combo_apos].height*16;
7586
7587 textprintf_shadowed_ex(brushbmp, get_zc_font(font_sfont), xoff, yoff, vc(15), vc(0), -1, "x");
7588 }
7589 else if(draw_mode != dm_cpool)
7590 {
7591 int32_t cid = combobrushoverride > -1 ? combobrushoverride : Combo;
7592 int32_t c = 0;
7593
7594 for(int32_t i=0; i<256; i++)
7595 {
7596 if(unsigned(cid+c) >= MAXCOMBOS) break;
7597 if(((i%COMBOS_PER_ROW)<BrushWidth)&&((i/COMBOS_PER_ROW)<BrushHeight))
7598 {
7599 put_combo(brushbmp,(i%COMBOS_PER_ROW)<<4,(i/COMBOS_PER_ROW)<<4,cid+c,CSet,Flags&(cFLAGS|cWALK),0);
7600 }
7601
7602 if(((cid+c)&3)==3)
7603 c+=48;
7604
7605 ++c;
7606
7607 if((i%COMBOS_PER_ROW)==(COMBOS_PER_ROW-1))
7608 c-=256;
7609 }
7610 }
7611 }
7612
7613 byte relational_source_grid[256]=
7614 {
7615 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
7616 16, 16, 17, 17, 18, 18, 19, 19, 16, 16, 17, 17, 18, 18, 19, 19,
7617 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 23, 23, 23, 23,
7618 24, 24, 24, 24, 25, 25, 25, 25, 24, 24, 24, 24, 25, 25, 25, 25,
7619 26, 27, 26, 27, 26, 27, 26, 27, 28, 29, 28, 29, 28, 29, 28, 29,
7620 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
7621 31, 31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32,
7622 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
7623 34, 35, 36, 37, 34, 35, 36, 37, 34, 35, 36, 37, 34, 35, 36, 37,
7624 38, 38, 39, 39, 38, 38, 39, 39, 38, 38, 39, 39, 38, 38, 39, 39,
7625 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40,
7626 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41,
7627 42, 43, 42, 43, 42, 43, 42, 43, 42, 43, 42, 43, 42, 43, 42, 43,
7628 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
7629 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
7630 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46
7631 };
7632
7633 static void draw_autocombo(ComboPosition combo_pos, bool rclick, bool pressframe = false)
7634 {
7635 combo_auto &ca = combo_autos[combo_auto_pos];
7636 int screen = Map.getScreenForPosition(combo_pos);
7637 int pos = combo_pos.truncate();
7638
7639 if (ca.valid())
7640 {
7641 switch (ca.getType())
7642 {
7643 case AUTOCOMBO_BASIC:
7644 {
7645 AutoPattern::autopattern_basic ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7646 if (rclick)
7647 ap.erase(screen, pos);
7648 else
7649 ap.execute(screen, pos);
7650 break;
7651 }
7652 case AUTOCOMBO_Z1:
7653 {
7654 AutoPattern::autopattern_flatmtn ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7655 if (rclick)
7656 ap.erase(screen, pos);
7657 else
7658 ap.execute(screen, pos);
7659 break;
7660 }
7661 case AUTOCOMBO_FENCE:
7662 {
7663 AutoPattern::autopattern_fence ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7664 if (rclick)
7665 ap.erase(screen, pos);
7666 else
7667 ap.execute(screen, pos);
7668 break;
7669 }
7670 case AUTOCOMBO_Z4:
7671 {
7672 AutoPattern::autopattern_cakemtn ap(ca.getType(), CurrentLayer, screen, pos, &ca, cauto_height);
7673 if (rclick)
7674 ap.erase(screen, pos);
7675 else
7676 ap.execute(screen, pos);
7677 break;
7678 }
7679 case AUTOCOMBO_RELATIONAL:
7680 {
7681 AutoPattern::autopattern_relational ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7682 if (rclick)
7683 ap.erase(screen, pos);
7684 else
7685 ap.execute(screen, pos);
7686 break;
7687 }
7688 case AUTOCOMBO_DGNCARVE:
7689 {
7690 AutoPattern::autopattern_dungeoncarve ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7691 if (rclick)
7692 ap.erase(screen, pos);
7693 else
7694 ap.execute(screen, pos);
7695 break;
7696 }
7697 case AUTOCOMBO_DOR:
7698 {
7699 AutoPattern::autopattern_dormtn ap(ca.getType(), CurrentLayer, screen, pos, &ca, cauto_height);
7700 if (rclick)
7701 ap.erase(screen, pos);
7702 else
7703 ap.execute(screen, pos);
7704 break;
7705 }
7706 case AUTOCOMBO_TILING:
7707 {
7708 if (pressframe && (key[KEY_LSHIFT] || key[KEY_RSHIFT]))
7709 {
7710 int32_t x = (screen % 16) * 16 + (pos % 16);
7711 int32_t y = (screen / 16) * 11 + (pos / 16);
7712 byte w = (ca.getArg() & 0xF) + 1;
7713 byte h = ((ca.getArg() >> 4) & 0xF) + 1;
7714 ca.setOffsets(x % w, y % h);
7715 }
7716 AutoPattern::autopattern_tiling ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7717 if (rclick)
7718 ap.erase(screen, pos);
7719 else
7720 ap.execute(screen, pos);
7721 break;
7722 }
7723 case AUTOCOMBO_REPLACE:
7724 {
7725 AutoPattern::autopattern_replace ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7726 if (rclick)
7727 ap.erase(screen, pos);
7728 else
7729 ap.execute(screen, pos);
7730 break;
7731 }
7732 case AUTOCOMBO_DENSEFOREST:
7733 {
7734 if (pressframe && (key[KEY_LSHIFT] || key[KEY_RSHIFT]))
7735 {
7736 int32_t x = (screen % 16) * 16 + (pos % 16);
7737 int32_t y = (screen / 16) * 11 + (pos / 16);
7738 ca.setOffsets(x % 2, y % 2);
7739 }
7740 AutoPattern::autopattern_denseforest ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7741 if (rclick)
7742 ap.erase(screen, pos);
7743 else
7744 ap.execute(screen, pos);
7745 break;
7746 }
7747 case AUTOCOMBO_EXTEND:
7748 {
7749 if (CHECK_CTRL_CMD)
7750 break;
7751 AutoPattern::autopattern_extend ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7752 if (rclick)
7753 ap.erase(screen, pos);
7754 else
7755 ap.execute(screen, pos);
7756 break;
7757 }
7758 }
7759 }
7760 else
7761 {
7762 ca.updateValid();
7763 if(!ca.valid())
7764 InfoDialog("Notice", "The autocombo you're trying to use is invalid. Reason:"
7765 + ca.getInvalidReason()).show();
7766 }
7767 }
7768
7769 static void draw_autocombo_command(ComboPosition combo_pos, int32_t cmd = 0, int32_t arg = 0)
7770 {
7771 combo_auto ca = combo_autos[combo_auto_pos];
7772 int screen = Map.getScreenForPosition(combo_pos);
7773 int pos = combo_pos.truncate();
7774
7775 if (ca.valid())
7776 {
7777 switch (ca.getType())
7778 {
7779 case AUTOCOMBO_FENCE:
7780 {
7781 AutoPattern::autopattern_fence ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7782 ap.flip_all_connected(screen, pos, 2048);
7783 break;
7784 }
7785 case AUTOCOMBO_Z4:
7786 {
7787 AutoPattern::autopattern_cakemtn ap(ca.getType(), CurrentLayer, screen, pos, &ca, cauto_height);
7788 switch (cmd)
7789 {
7790 case 0: // Flip
7791 ap.flip_all_connected(screen, pos, 2048);
7792 break;
7793 case 1: // Grow
7794 ap.resize_connected(screen, pos, 2048, vbound(arg, 1, 9));
7795 break;
7796 }
7797 }
7798 }
7799 }
7800 }
7801
7802 static int32_t get_autocombo_floating_cid(ComboPosition combo_pos, bool clicked)
7803 {
7804 combo_auto& ca = combo_autos[combo_auto_pos];
7805 int screen = Map.getScreenForPosition(combo_pos);
7806 int pos = combo_pos.truncate();
7807 int cid = 0;
7808
7809 if (ca.valid() && Map.isValidPosition(mouse_combo_pos))
7810 {
7811 switch (ca.getType())
7812 {
7813 case AUTOCOMBO_BASIC:
7814 {
7815 AutoPattern::autopattern_basic ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7816 cid = ap.get_floating_cid(screen, pos);
7817 break;
7818 }
7819
7820 case AUTOCOMBO_Z1:
7821 {
7822 AutoPattern::autopattern_flatmtn ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7823 cid = ap.get_floating_cid(screen, pos);
7824 break;
7825 }
7826 case AUTOCOMBO_FENCE:
7827 {
7828 AutoPattern::autopattern_fence ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7829 cid = ap.get_floating_cid(screen, pos);
7830 break;
7831 }
7832 case AUTOCOMBO_Z4:
7833 {
7834 AutoPattern::autopattern_cakemtn ap(ca.getType(), CurrentLayer, screen, pos, &ca, cauto_height);
7835 cid = ap.get_floating_cid(screen, pos);
7836 break;
7837 }
7838 case AUTOCOMBO_RELATIONAL:
7839 {
7840 AutoPattern::autopattern_relational ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7841 cid = ap.get_floating_cid(screen, pos);
7842 break;
7843 }
7844 case AUTOCOMBO_DGNCARVE:
7845 {
7846 AutoPattern::autopattern_dungeoncarve ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7847 cid = ap.get_floating_cid(screen, pos);
7848 break;
7849 }
7850 case AUTOCOMBO_DOR:
7851 {
7852 AutoPattern::autopattern_dormtn ap(ca.getType(), CurrentLayer, screen, pos, &ca, cauto_height);
7853 cid = ap.get_floating_cid(screen, pos);
7854 break;
7855 }
7856 case AUTOCOMBO_TILING:
7857 {
7858 std::pair<byte, byte> offs = ca.getOffsets();
7859 if (!clicked && (key[KEY_LSHIFT] || key[KEY_RSHIFT]))
7860 {
7861 int32_t x = (screen % 16) * 16 + (pos % 16);
7862 int32_t y = (screen / 16) * 11 + (pos / 16);
7863 byte w = (ca.getArg() & 0xF) + 1;
7864 byte h = ((ca.getArg() >> 4) & 0xF) + 1;
7865 offs.first = (x % w);
7866 offs.second = (y % h);
7867 }
7868 AutoPattern::autopattern_tiling ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7869 cid = ap.get_floating_cid(screen, pos);
7870 break;
7871 }
7872 case AUTOCOMBO_REPLACE:
7873 {
7874 AutoPattern::autopattern_replace ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7875 cid = ap.get_floating_cid(screen, pos);
7876 break;
7877 }
7878 case AUTOCOMBO_DENSEFOREST:
7879 {
7880 AutoPattern::autopattern_denseforest ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7881 cid = ap.get_floating_cid(screen, pos);
7882 break;
7883 }
7884 case AUTOCOMBO_EXTEND:
7885 {
7886 AutoPattern::autopattern_extend ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7887 cid = ap.get_floating_cid(screen, pos);
7888 break;
7889 }
7890 }
7891 }
7892 return cid;
7893 }
7894
7895 void change_autocombo_height(int32_t change)
7896 {
7897 bool can_change = false;
7898 if (draw_mode == dm_auto)
7899 {
7900 combo_auto ca = combo_autos[combo_auto_pos];
7901 switch (ca.getType())
7902 {
7903 case AUTOCOMBO_Z4:
7904 can_change = true;
7905 [[fallthrough]];
7906 case AUTOCOMBO_DOR:
7907 break;
7908 default:
7909 return;
7910 }
7911 }
7912 else
7913 return;
7914
7915 int32_t x = gui_mouse_x();
7916 int32_t y = gui_mouse_y();
7917 double startx = mapscreen_x + (showedges ? (16 * mapscreen_single_scale) : 0);
7918 double starty = mapscreen_y + (showedges ? (16 * mapscreen_single_scale) : 0);
7919 int32_t startxint = mapscreen_x + (showedges ? int32_t(16 * mapscreen_single_scale) : 0);
7920 int32_t startyint = mapscreen_y + (showedges ? int32_t(16 * mapscreen_single_scale) : 0);
7921 ComboPosition pos = get_mapscreen_mouse_combo_pos();
7922
7923 if (can_change && isinRect(x, y, startxint, startyint, int32_t(startx + (256 * mapscreen_single_scale) - 1), int32_t(starty + (176 * mapscreen_single_scale) - 1)))
7924 {
7925 Map.StartListCommand();
7926 draw_autocombo_command(pos, 1, cauto_height + change);
7927 Map.FinishListCommand();
7928 }
7929 cauto_height = vbound(cauto_height + change, 1, 9);
7930 }
7931
7932 void draw(bool justcset)
7933 {
7934 combo_pool const& pool = combo_pools[combo_pool_pos];
7935 if(draw_mode == dm_cpool && !pool.valid())
7936 return;
7937 saved=false;
7938
7939 refresh(rMAP+rSCRMAP);
7940 ComboPosition last_pos = {-1, -1};
7941
7942 Map.StartListCommand();
7943 bool pressframe = true;
7944 while(gui_mouse_b())
7945 {
7946 int32_t x=gui_mouse_x();
7947 int32_t y=gui_mouse_y();
7948 double startx=mapscreen_x+(showedges?(16*mapscreen_single_scale):0);
7949 double starty=mapscreen_y+(showedges?(16*mapscreen_single_scale):0);
7950 int32_t startxint=mapscreen_x+(showedges?int32_t(16*mapscreen_single_scale):0);
7951 int32_t startyint=mapscreen_y+(showedges?int32_t(16*mapscreen_single_scale):0);
7952 int num_combos_width = 16 * Map.getViewSize();
7953 int num_combos_height = 11 * Map.getViewSize();
7954
7955 if(isinRect(x,y,startxint,startyint,int32_t(startx+(256*mapscreen_screenunit_scale)-1),int32_t(starty+(176*mapscreen_screenunit_scale)-1)))
7956 {
7957 int32_t cxstart=(x-startx)/(16*mapscreen_single_scale);
7958 int32_t cystart=(y-starty)/(16*mapscreen_single_scale);
7959 ComboPosition combo_start = {cxstart, cystart};
7960 if (pressframe)
7961 {
7962 last_pos = combo_start;
7963 }
7964 else if (combo_start == last_pos)
7965 {
7966 custom_vsync();
7967 refresh(rALL);
7968 continue;
7969 }
7970 else if(draw_mode == dm_auto)
7971 {
7972 // TODO: support when zoomed out.
7973 if (combo_autos[combo_auto_pos].getType() == AUTOCOMBO_FENCE || combo_autos[combo_auto_pos].getType() == AUTOCOMBO_Z4)
7974 {
7975 // Don't allow moving the brush at anything but cardinal directions while in these modes
7976 bool did_diag = std::abs(combo_start.x - last_pos.x) == 1 && std::abs(combo_start.y - last_pos.y) == 1;
7977
7978 if (did_diag)
7979 {
7980 int32_t oldx = last_pos.x;
7981 int32_t oldy = last_pos.y;
7982 int32_t cx = (oldx * 16 * mapscreen_single_scale) + 8;
7983 int32_t cy = (oldy * 16 * mapscreen_single_scale) + 8;
7984 int32_t nx = x - startxint;
7985 int32_t ny = y - startyint;
7986 if (std::abs(nx - cx) < std::abs(ny - cy))
7987 {
7988 oldy = vbound(oldy + ((ny - cy) < 0 ? -1 : 1), 0, 11);
7989 }
7990 else
7991 {
7992 oldx = vbound(oldx + ((nx - cx) < 0 ? -1 : 1), 0, 15);
7993 }
7994 combo_start = {oldx, oldy};
7995 }
7996 }
7997 }
7998 last_pos = combo_start;
7999
8000 switch(draw_mode)
8001 {
8002 case dm_normal:
8003 {
8004 int32_t cc=Combo;
8005
8006 for(int32_t cy=0; cy+cystart<num_combos_height&&cy<BrushHeight; cy++)
8007 {
8008 for(int32_t cx=0; cx+cxstart<num_combos_width&&cx<BrushWidth; cx++)
8009 {
8010 auto pos = combo_start + ComboPosition{cx, cy};
8011 cc=Combo + cx + cy*4;
8012 Map.DoSetComboCommand(pos, justcset ? -1 : cc, CSet);
8013 }
8014 }
8015
8016 update_combobrush();
8017 }
8018 break;
8019 case dm_cpool:
8020 {
8021 int32_t cid = Combo;
8022 int8_t cs = CSet;
8023 pool.pick(cid,cs);
8024 Map.DoSetComboCommand(combo_start, justcset ? -1 : cid, cs);
8025
8026 update_combobrush();
8027 }
8028 break;
8029
8030 case dm_alias:
8031 {
8032 combo_alias *combo = &combo_aliases[combo_apos];
8033 if(!combo->layermask)
8034 {
8035 int32_t ox=0, oy=0;
8036
8037 switch(alias_origin)
8038 {
8039 case 0:
8040 ox=0;
8041 oy=0;
8042 break;
8043
8044 case 1:
8045 ox=(combo->width);
8046 oy=0;
8047 break;
8048
8049 case 2:
8050 ox=0;
8051 oy=(combo->height);
8052 break;
8053
8054 case 3:
8055 ox=(combo->width);
8056 oy=(combo->height);
8057 break;
8058 }
8059
8060 for(int32_t cy=0; cy-oy+cystart<num_combos_height&&cy<=combo->height; cy++)
8061 {
8062 for(int32_t cx=0; cx-ox+cxstart<num_combos_width&&cx<=combo->width; cx++)
8063 {
8064 if((cx+cxstart-ox>=0)&&(cy+cystart-oy>=0))
8065 {
8066 int32_t p=(cy*(combo->width+1))+cx;
8067
8068 if(combo->combos[p])
8069 {
8070 auto pos = combo_start + ComboPosition{cx - ox, cy - oy};
8071 Map.DoSetComboCommand(pos, combo->combos[p], wrap(combo->csets[p]+alias_cset_mod, 0, 13));
8072 }
8073 }
8074 }
8075 }
8076 }
8077 else
8078 {
8079 int32_t laypos = 0;
8080 int32_t ox=0, oy=0;
8081
8082 switch(alias_origin)
8083 {
8084 case 0:
8085 ox=0;
8086 oy=0;
8087 break;
8088
8089 case 1:
8090 ox=(combo->width);
8091 oy=0;
8092 break;
8093
8094 case 2:
8095 ox=0;
8096 oy=(combo->height);
8097 break;
8098
8099 case 3:
8100 ox=(combo->width);
8101 oy=(combo->height);
8102 break;
8103 }
8104
8105 for(int32_t cz=0; cz<7; cz++)
8106 {
8107 if (cz > 0 && !(combo->layermask & (1<<(cz-1))))
8108 continue;
8109
8110 if (cz > 0)
8111 laypos++;
8112
8113 for(int32_t cy=0; cy-oy+cystart<num_combos_height&&cy<=combo->height; cy++)
8114 {
8115 for(int32_t cx=0; cx-ox+cxstart<num_combos_width&&cx<=combo->width; cx++)
8116 {
8117 if((cx+cxstart-ox>=0)&&(cy+cystart-oy>=0))
8118 {
8119 int32_t p=((cy*(combo->width+1))+cx)+((combo->width+1)*(combo->height+1)*laypos);
8120
8121 if (combo->combos[p])
8122 {
8123 auto pos = combo_start + ComboPosition{cx - ox, cy - oy};
8124 if(cz > 0 && Map.Scr(pos)->layermap[cz - 1] == 0)
8125 continue;
8126 int prev = CurrentLayer;
8127 CurrentLayer = cz;
8128 Map.DoSetComboCommand(pos, combo->combos[p], wrap(combo->csets[p]+alias_cset_mod, 0, 13));
8129 CurrentLayer = prev;
8130 }
8131 }
8132 }
8133 }
8134 }
8135 }
8136
8137 break;
8138 }
8139
8140 case dm_auto:
8141 {
8142 draw_autocombo(combo_start, gui_mouse_b() & 2, pressframe);
8143
8144 combobrushoverride = get_autocombo_floating_cid(combo_start, true);
8145 update_combobrush();
8146 }
8147 }
8148 }
8149 pressframe = false;
8150
8151 custom_vsync();
8152 refresh(rALL);
8153 }
8154
8155 Map.FinishListCommand();
8156 if(AutoBrushRevert)
8157 {
8158 AutoBrushRevert = false;
8159 BrushWidth = 1;
8160 BrushHeight = 1;
8161 }
8162 }
8163
8164 static void replace(ComboPosition start)
8165 {
8166 int32_t cid = Combo;
8167 int8_t cs = CSet;
8168 combo_pool const& pool = combo_pools[combo_pool_pos];
8169 if(draw_mode == dm_cpool && !pool.valid())
8170 return;
8171
8172 int c = start.truncate();
8173 mapscr* scr = Map.Scr(start, CurrentLayer);
8174 if (!scr) return;
8175
8176 int num_combos_width = 16 * Map.getViewSize();
8177 int num_combos_height = 11 * Map.getViewSize();
8178 int targetcombo = scr->data[c];
8179 int targetcset = scr->cset[c];
8180
8181 saved = false;
8182 Map.StartListCommand();
8183 if(key[KEY_LSHIFT] || key[KEY_RSHIFT])
8184 {
8185 for (int x = 0; x < num_combos_width; x++)
8186 {
8187 for (int y = 0; y < num_combos_height; y++)
8188 {
8189 ComboPosition pos = {x, y};
8190 int c = pos.truncate();
8191 mapscr* scr = Map.Scr(pos, CurrentLayer);
8192 if (!scr)
8193 continue;
8194
8195 if ((scr->cset[c]) == targetcset)
8196 {
8197 if(draw_mode == dm_cpool)
8198 pool.pick(cid,cs);
8199 Map.DoSetComboCommand(pos, -1, cs);
8200 }
8201 }
8202 }
8203 }
8204 else
8205 {
8206 for (int x = 0; x < num_combos_width; x++)
8207 {
8208 for (int y = 0; y < num_combos_height; y++)
8209 {
8210 ComboPosition pos = {x, y};
8211 int c = pos.truncate();
8212 mapscr* scr = Map.Scr(pos, CurrentLayer);
8213 if (!scr)
8214 continue;
8215
8216 if(((scr->data[c])==targetcombo) &&
8217 ((scr->cset[c])==targetcset))
8218 {
8219 if(draw_mode == dm_cpool)
8220 pool.pick(cid,cs);
8221 Map.DoSetComboCommand(pos, cid, cs);
8222 }
8223 }
8224 }
8225 }
8226 Map.FinishListCommand();
8227
8228 refresh(rMAP);
8229 }
8230
8231 static void draw_block(ComboPosition start, int32_t w, int32_t h)
8232 {
8233 int32_t cid = Combo;
8234 int8_t cs = CSet;
8235 if(draw_mode == dm_cpool)
8236 {
8237 combo_pool const& pool = combo_pools[combo_pool_pos];
8238 if(!pool.pick(cid,cs)) return;
8239 }
8240
8241 mapscr* scr = Map.Scr(start, CurrentLayer);
8242 if (!scr) return;
8243
8244 saved = false;
8245 Map.StartListCommand();
8246 for (int32_t y=0; y < h && y < 11*Map.getViewSize(); y++)
8247 for (int32_t x=0; x < w && x < 16*Map.getViewSize(); x++)
8248 {
8249 Map.DoSetComboCommand(start + ComboPosition{x, y}, cid+(y*4)+x, cs);
8250 }
8251
8252 Map.FinishListCommand();
8253 refresh(rMAP+rSCRMAP);
8254 }
8255
8256 static std::vector<ComboPosition> flood_filler(ComboPosition start_pos, bool allow_diagonal, std::function<bool(ComboPosition)> check)
8257 {
8258 std::vector<ComboPosition> seen, queue;
8259
8260 queue.push_back(start_pos);
8261 while (!queue.empty())
8262 {
8263 ComboPosition pos = queue.back();
8264 queue.pop_back();
8265 seen.push_back(pos);
8266
8267 ComboPosition pos2;
8268 #define FLOOD_FILLER_CHECK(dx, dy)\
8269 pos2 = pos + ComboPosition{dx, dy};\
8270 if (std::find(seen.begin(), seen.end(), pos2) == seen.end() && check(pos2))\
8271 queue.push_back(pos2);
8272
8273 FLOOD_FILLER_CHECK(0, 1);
8274 FLOOD_FILLER_CHECK(0, -1);
8275 FLOOD_FILLER_CHECK(1, 0);
8276 FLOOD_FILLER_CHECK(-1, 0);
8277
8278 if (allow_diagonal)
8279 {
8280 FLOOD_FILLER_CHECK(1, 1);
8281 FLOOD_FILLER_CHECK(1, -1);
8282 FLOOD_FILLER_CHECK(-1, 1);
8283 FLOOD_FILLER_CHECK(-1, -1);
8284 }
8285
8286 #undef FLOOD_FILLER_CHECK
8287 }
8288
8289 return seen;
8290 }
8291
8292 static void fill(int32_t targetcombo, int32_t targetcset, ComboPosition start_pos, bool allow_diagonal, bool only_cset)
8293 {
8294 bool rclick = gui_mouse_b() & 2;
8295 bool ignored_combo = false;
8296
8297 mapscr* scr = Map.ScrMakeValid(start_pos, CurrentLayer);
8298 if (!scr)
8299 return;
8300
8301 int num_combos_width = 16 * Map.getViewSize();
8302 int num_combos_height = 11 * Map.getViewSize();
8303
8304 auto combo_positions = flood_filler(start_pos, allow_diagonal, [&](ComboPosition pos){
8305 if (pos.x < 0 || pos.y < 0 || pos.x >= num_combos_width || pos.y >= num_combos_height)
8306 return false;
8307
8308 mapscr* scr = Map.Scr(pos, CurrentLayer);
8309 if (!scr || !scr->is_valid())
8310 return false;
8311
8312 int cid = scr->data[pos.truncate()];
8313 int cset = scr->cset[pos.truncate()];
8314
8315 if (draw_mode == dm_auto)
8316 {
8317 combo_auto const& cauto = combo_autos[combo_auto_pos];
8318
8319 ignored_combo = cauto.isIgnoredCombo(cid);
8320 if (rclick)
8321 {
8322 if (cauto.containsCombo(targetcombo))
8323 {
8324 if (!cauto.containsCombo(cid))
8325 return false;
8326 if (cauto.getType() == AUTOCOMBO_REPLACE && ignored_combo)
8327 return false;
8328 }
8329 else
8330 return false;
8331 }
8332 else
8333 {
8334 if (cid != targetcombo && !ignored_combo)
8335 return false;
8336 if (cauto.getType() == AUTOCOMBO_REPLACE && !ignored_combo)
8337 return false;
8338 }
8339
8340 if (cset != targetcset && !ignored_combo)
8341 return false;
8342 }
8343 else
8344 {
8345 if(!only_cset)
8346 {
8347 if (cid != targetcombo)
8348 return false;
8349 }
8350
8351 if (cset != targetcset)
8352 return false;
8353 }
8354
8355 return true;
8356 });
8357
8358 for (auto& pos : combo_positions)
8359 {
8360 int32_t cid = Combo;
8361 int8_t cs = CSet;
8362
8363 if (draw_mode == dm_cpool)
8364 {
8365 combo_pool const& pool = combo_pools[combo_pool_pos];
8366 if (!pool.pick(cid, cs)) continue;
8367 }
8368 else if (draw_mode == dm_auto)
8369 {
8370 combo_auto const& cauto = combo_autos[combo_auto_pos];
8371 if (!cauto.valid())
8372 continue;
8373 if (!rclick && (cauto.containsCombo(targetcombo) && !ignored_combo))
8374 continue;
8375 if (rclick && cauto.getEraseCombo() == targetcombo)
8376 continue;
8377 }
8378
8379 if (draw_mode == dm_auto)
8380 draw_autocombo(pos, rclick);
8381 else
8382 Map.DoSetComboCommand(pos, only_cset ? -1 : cid, cs);
8383 }
8384 }
8385
8386 static void fill_flag(int32_t targetflag, ComboPosition start_pos, bool allow_diagonal)
8387 {
8388 mapscr* scr = Map.ScrMakeValid(start_pos, CurrentLayer);
8389 if (!scr)
8390 return;
8391
8392 int num_combos_width = 16 * Map.getViewSize();
8393 int num_combos_height = 11 * Map.getViewSize();
8394
8395 auto combo_positions = flood_filler(start_pos, allow_diagonal, [&](ComboPosition pos){
8396 if (pos.x < 0 || pos.y < 0 || pos.x >= num_combos_width || pos.y >= num_combos_height)
8397 return false;
8398
8399 mapscr* scr = Map.Scr(pos, CurrentLayer);
8400 if (!scr || !scr->is_valid())
8401 return false;
8402
8403 if (scr->sflag[pos.truncate()] != targetflag)
8404 return false;
8405
8406 return true;
8407 });
8408
8409 for (auto& pos : combo_positions)
8410 Map.DoSetFlagCommand(pos, Flag);
8411 }
8412
8413 static void fill2(int32_t targetcombo, int32_t targetcset, ComboPosition pos, int32_t dir, int32_t diagonal, bool only_cset)
8414 {
8415 mapscr* scr = Map.Scr(pos, CurrentLayer);
8416 if (!scr || !scr->is_valid())
8417 return;
8418
8419 int cid = scr->data[pos.truncate()];
8420 int cset = scr->cset[pos.truncate()];
8421
8422 if (!only_cset)
8423 {
8424 if (cid == targetcombo)
8425 return;
8426 }
8427
8428 if (cset == targetcset)
8429 return;
8430
8431 cid = Combo;
8432 int8_t cs = CSet;
8433 if(draw_mode == dm_cpool)
8434 {
8435 combo_pool const& pool = combo_pools[combo_pool_pos];
8436 if(!pool.pick(cid,cs)) return;
8437 }
8438
8439 Map.DoSetComboCommand(pos, only_cset ? -1 : cid, cs);
8440
8441 int num_combos_width = 16 * Map.getViewSize();
8442 int num_combos_height = 11 * Map.getViewSize();
8443
8444 if (pos.y > 0 && dir != down)
8445 fill2(targetcombo, targetcset, pos + ComboPosition{0, -1}, up, diagonal, only_cset);
8446 if (pos.y < num_combos_height-1 && dir != up)
8447 fill2(targetcombo, targetcset, pos + ComboPosition{0, 1}, down, diagonal, only_cset);
8448 if (pos.x > 0 && dir != right)
8449 fill2(targetcombo, targetcset, pos + ComboPosition{-1, 0}, left, diagonal, only_cset);
8450 if (pos.x < num_combos_width-1 && dir != left)
8451 fill2(targetcombo, targetcset, pos + ComboPosition{1, 0}, right, diagonal, only_cset);
8452
8453 if (diagonal == 1)
8454 {
8455 if (pos.y > 0 && pos.x > 0 && dir != r_down)
8456 fill2(targetcombo, targetcset, pos + ComboPosition{-1, -1}, l_up, diagonal, only_cset);
8457 if (pos.y < num_combos_height-1 && pos.x < num_combos_width-1 && dir != l_up)
8458 fill2(targetcombo, targetcset, pos + ComboPosition{1, 1}, r_down, diagonal, only_cset);
8459 if (pos.x > 0 && pos.y < num_combos_height-1 && dir != r_up)
8460 fill2(targetcombo, targetcset, pos + ComboPosition{-1, 1}, l_down, diagonal, only_cset);
8461 if (pos.x < num_combos_width-1 && pos.y > 0 && dir != l_down)
8462 fill2(targetcombo, targetcset, pos + ComboPosition{1, -1}, r_up, diagonal, only_cset);
8463 }
8464 }
8465
8466
8467 enum SnapMode
8468 {
8469 SNAP_NONE, SNAP_HALF, SNAP_WHOLE
8470 };
8471 static void snap_xy(int& x, int& y, SnapMode mode, roundType rounding, optional<int> max_x = nullopt, optional<int> max_y = nullopt)
8472 {
8473 if(mode == SNAP_NONE)
8474 {
8475 if(max_x) x = vbound(x,*max_x,0);
8476 if(max_y) y = vbound(y,*max_y,0);
8477 return;
8478 }
8479 int xoff = 0, yoff = 0;
8480 switch(rounding)
8481 {
8482 case ROUND_TO_0:
8483 rounding = ROUND_DOWN;
8484 break;
8485 case ROUND_AWAY_0:
8486 rounding = ROUND_UP;
8487 break;
8488 }
8489 int r = 0;
8490 switch(mode)
8491 {
8492 case SNAP_HALF:
8493 r = 8;
8494 break;
8495 case SNAP_WHOLE:
8496 r = 16;
8497 break;
8498 }
8499 assert(r > 0);
8500 // r must be a power of 2, for bitwise reasons
8501 switch(rounding)
8502 {
8503 case ROUND_DOWN:
8504 break;
8505 case ROUND_UP:
8506 xoff = ((x & (r-1)) ? r : 0);
8507 yoff = ((y & (r-1)) ? r : 0);
8508 break;
8509 case ROUND_NEAREST:
8510 xoff = ((x & (r-1)) >= (r/2) ? r : 0);
8511 yoff = ((y & (r-1)) >= (r/2) ? r : 0);
8512 break;
8513 }
8514 x = (x & ~(r-1)) + xoff;
8515 y = (y & ~(r-1)) + yoff;
8516 if(max_x && x >= *max_x) x = *max_x-r;
8517 else if(max_x && x < 0) x = 0;
8518 if(max_y && y >= *max_y) y = *max_y-r;
8519 else if(max_y && y < 0) y = 0;
8520 }
8521
8522 static void doxypos(byte &px2, byte &py2, int32_t color, SnapMode snap_mode,
8523 SnapMode shift_mode, bool immediately, int32_t cursoroffx,
8524 int32_t cursoroffy, int32_t iconw, int32_t iconh)
8525 {
8526 int32_t tempcb=ComboBrush;
8527 ComboBrush=0;
8528 MouseSprite::set(ZQM_POINT_BOX);
8529
8530 int viz_off_x = (active_visible_screen ? active_visible_screen->dx * 256 : 0);
8531 int viz_off_y = (active_visible_screen ? active_visible_screen->dy * 176 : 0);
8532
8533 int32_t oldpx=px2, oldpy=py2;
8534 int32_t startxint=mapscreen_x+(showedges?int32_t(16*mapscreen_single_scale):0);
8535 int32_t startyint=mapscreen_y+(showedges?int32_t(16*mapscreen_single_scale):0);
8536 showxypos_x=px2 + viz_off_x;
8537 showxypos_y=py2 + viz_off_y;
8538 showxypos_w=iconw;
8539 showxypos_h=iconh;
8540 showxypos_color=vc(color);
8541 showxypos_icon=!showxypos_dummy;
8542 bool canedit=false;
8543 bool done=false;
8544
8545 clear_tooltip();
8546
8547 while(!done && (!(gui_mouse_b()&2) || immediately))
8548 {
8549 if(!gui_mouse_b() || immediately)
8550 {
8551 canedit=true;
8552 }
8553
8554 // TODO: would be nice if these bounds were based on the individual screen.
8555 if(canedit && gui_mouse_b()==1 && isinRect(gui_mouse_x(),gui_mouse_y(),startxint,startyint,(startxint+(256*mapscreen_screenunit_scale)-1),(startyint+(176*mapscreen_screenunit_scale)-1)))
8556 {
8557 set_mouse_range(startxint,startyint,int32_t(startxint+(256*mapscreen_screenunit_scale)-1),int32_t(startyint+(176*mapscreen_screenunit_scale)-1));
8558
8559 double offx = 0, offy = 0;
8560 roundType rounding = ROUND_DOWN;
8561 if(DragCenterOfSquares)
8562 {
8563 offx -= iconw*mapscreen_single_scale/2;
8564 offy -= iconh*mapscreen_single_scale/2;
8565 rounding = ROUND_NEAREST;
8566 }
8567 int32_t x, y;
8568 do
8569 {
8570 x=int32_t((gui_mouse_x()-startxint+offx)/mapscreen_single_scale)-cursoroffx;
8571 y=int32_t((gui_mouse_y()-startyint+offy)/mapscreen_single_scale)-cursoroffy;
8572 showxypos_cursor_icon=true;
8573 showxypos_cursor_color = showxypos_color;
8574 auto _mode = (key[KEY_LSHIFT] || key[KEY_RSHIFT]) ? shift_mode : snap_mode;
8575 showxypos_cursor_x = x-viz_off_x;
8576 showxypos_cursor_y = y-viz_off_y;
8577 snap_xy(showxypos_cursor_x, showxypos_cursor_y, _mode, rounding, 256, 176);
8578 showxypos_cursor_x += viz_off_x;
8579 showxypos_cursor_y += viz_off_y;
8580 custom_vsync();
8581 refresh(rALL | rNOCURSOR);
8582 int32_t xpos[2], ypos[2];
8583 int32_t x1,y1,x2,y2;
8584
8585 char b1[200] = {0};
8586 char b2[200] = {0};
8587 if(showxypos_dummy)
8588 strcpy(b1, "DUMMY MEASURING");
8589 else sprintf(b1, "%d %d",oldpx,oldpy);
8590 sprintf(b2, "%d %d (%d %d)",x-viz_off_x,y-viz_off_y,showxypos_cursor_x-viz_off_x,showxypos_cursor_y-viz_off_y);
8591
8592 int len[2] = {text_length(font,b1),text_length(font,b2)};
8593
8594 if(is_compact)
8595 {
8596 xpos[0] = 4;
8597 ypos[0] = layer_panel.y - 21;
8598 xpos[1] = xpos[0];
8599 ypos[1] = ypos[0]+10;
8600 }
8601 else
8602 {
8603 xpos[0] = 450;
8604 ypos[0] = 405;
8605 xpos[1] = xpos[0];
8606 ypos[1] = ypos[0]+10;
8607 }
8608
8609 x1 = xpos[0];
8610 y1 = ypos[0];
8611 x2 = xpos[0];
8612 y2 = ypos[0];
8613 for(auto q = 0; q < 2; ++q)
8614 {
8615 if(xpos[q] < x1)
8616 x1 = xpos[q];
8617 if(ypos[q] < y1)
8618 y1 = ypos[q];
8619 if(ypos[q] > y2)
8620 y2 = ypos[q];
8621 if(xpos[q] + len[q] > x2)
8622 x2 = xpos[q] + len[q];
8623 }
8624 x1 -= 4;
8625 y1 -= 2;
8626 y2 += text_height(font)+2;
8627
8628 auto minx = zc_min(xpos[0],xpos[1]);
8629 auto miny = zc_min(ypos[0],ypos[1]);
8630 rectfill(screen,x1,y1,x2,y2,vc(0));
8631 textprintf_ex(screen,font,xpos[0],ypos[0],vc(15),vc(0),"%s",b1);
8632 textprintf_ex(screen,font,xpos[1],ypos[1],vc(15),vc(0),"%s",b2);
8633 update_hw_screen();
8634 }
8635 while(gui_mouse_b()==1);
8636
8637 if(gui_mouse_b()==0)
8638 {
8639 auto _mode = (key[KEY_LSHIFT] || key[KEY_RSHIFT]) ? shift_mode : snap_mode;
8640 int x2 = vbound(x-viz_off_x,0,255);
8641 int y2 = vbound(y-viz_off_y,0,175);
8642 snap_xy(x2, y2, _mode, rounding, 256, 176);
8643 px2=byte(x2);
8644 py2=byte(y2);
8645 }
8646
8647 set_mouse_range(0,0,zq_screen_w-1,zq_screen_h-1);
8648 done=true;
8649 }
8650
8651 if(keypressed())
8652 {
8653 switch(readkey()>>8)
8654 {
8655 case KEY_ESC:
8656 case KEY_ENTER:
8657 goto finished;
8658 }
8659 }
8660
8661 custom_vsync();
8662 refresh(rALL | rNOCURSOR);
8663 }
8664
8665 finished:
8666 MouseSprite::set(ZQM_NORMAL);
8667 refresh(rMAP+rMENU);
8668
8669 while(gui_mouse_b())
8670 {
8671 /* do nothing */
8672 rest(1);
8673 }
8674
8675 showxypos_x=-1000;
8676 showxypos_y=-1000;
8677 showxypos_color=-1000;
8678 showxypos_ffc=-1000;
8679 showxypos_icon=false;
8680 showxypos_cursor_x=-1000;
8681 showxypos_cursor_y=-1000;
8682 showxypos_cursor_icon=false;
8683 showxypos_cursor_color=-1000;
8684 showxypos_dummy=false;
8685
8686 if(px2!=oldpx||py2!=oldpy)
8687 {
8688 saved=false;
8689 }
8690
8691 ComboBrush=tempcb;
8692 }
8693 static void doxypos(byte &px2,byte &py2,int32_t color,SnapMode snap_mode, optional<SnapMode> shift_mode = nullopt)
8694 {
8695 doxypos(px2,py2,color,snap_mode,shift_mode ? *shift_mode : snap_mode,false,0,0,16,16);
8696 }
8697
8698 bool placing_flags = false;
8699 void doflags()
8700 {
8701 placing_flags = true;
8702 int of=Flags;
8703 Flags=cFLAGS;
8704 refresh(rMAP | rNOCURSOR);
8705
8706 bool canedit=false;
8707 bool didShift = false;
8708 int tFlag = Flag;
8709 while(!(gui_mouse_b()&2) && !handle_close_btn_quit())
8710 {
8711 int x=gui_mouse_x();
8712 int y=gui_mouse_y();
8713 double startx=mapscreen_x+(showedges?(16*mapscreen_single_scale):0);
8714 double starty=mapscreen_y+(showedges?(16*mapscreen_single_scale):0);
8715 int startxint=mapscreen_x+(showedges?int(16*mapscreen_single_scale):0);
8716 int startyint=mapscreen_y+(showedges?int(16*mapscreen_single_scale):0);
8717 int cx=(x-startxint)/int(16*mapscreen_single_scale);
8718 int cy=(y-startyint)/int(16*mapscreen_single_scale);
8719 ComboPosition combo_pos = {cx, cy};
8720 int c = combo_pos.truncate();
8721
8722 if(!gui_mouse_b())
8723 canedit=true;
8724 bool shift = key[KEY_LSHIFT] || key[KEY_RSHIFT];
8725
8726 if(canedit && gui_mouse_b()==1 && isinRect(x,y,startxint,startyint,int(startx+(256*mapscreen_screenunit_scale)-1),int(starty+(176*mapscreen_screenunit_scale)-1)))
8727 {
8728 mapscr* cur_scr = Map.Scr(combo_pos, CurrentLayer);
8729 if (!cur_scr) continue;
8730
8731 Map.setCurrScr(Map.getScreenForPosition(combo_pos));
8732
8733 if(key[KEY_ALT]||key[KEY_ALTGR])
8734 Flag = cur_scr->sflag[c];
8735 else
8736 {
8737 saved=false;
8738 int tflag = Flag;
8739 if(shift)
8740 Flag = mfNONE;
8741 if(CurrentLayer!=0)
8742 {
8743 // Notify if they are using a flag that doesn't work on this layer.
8744 if(!skipLayerWarning && ((Flag >= mfTRAP_H && Flag < mfPUSHD) || (Flag == mfFAIRY) || (Flag == mfMAGICFAIRY)
8745 || (Flag == mfALLFAIRY) || (Flag == mfRAFT) || (Flag == mfRAFT_BRANCH)
8746 || (Flag == mfDIVE_ITEM) || (Flag == mfARMOS_SECRET) || (Flag == mfNOENEMY)
8747 || (Flag == mfZELDA)))
8748 {
8749 InfoDialog("Notice","You are currently working on layer "
8750 +to_string(CurrentLayer)
8751 +". This combo flag does not function on layers above '0'.").show();
8752 }
8753 if(!skipLayerWarning && CurrentLayer > 2 &&
8754 ((Flag == mfBLOCKHOLE) || (Flag >= mfPUSHD && Flag < mfNOBLOCKS)
8755 || (Flag == mfPUSHUD) || (Flag == mfPUSH4)))
8756 {
8757 InfoDialog("Notice","You are currently working on layer "
8758 +to_string(CurrentLayer)
8759 +". This combo flag does not function on layers above '2'.").show();
8760 }
8761 }
8762 if(CHECK_CTRL_CMD)
8763 {
8764 switch(fill_type)
8765 {
8766 case 0:
8767 flood_flag();
8768 break;
8769
8770 case 1:
8771 case 3:
8772 fill_4_flag();
8773 break;
8774
8775 case 2:
8776 case 4:
8777 fill_8_flag();
8778 break;
8779 }
8780 }
8781 else
8782 {
8783 Map.DoSetFlagCommand(combo_pos, Flag);
8784 }
8785 Flag = tflag;
8786 }
8787 }
8788
8789 if(mouse_z)
8790 {
8791 for(int i=0; i<abs(mouse_z); ++i)
8792 {
8793 if(mouse_z>0)
8794 onIncreaseFlag();
8795 else
8796 onDecreaseFlag();
8797 }
8798
8799 position_mouse_z(0);
8800 }
8801
8802 if(keypressed())
8803 {
8804 int k = readkey();
8805 switch(k>>8)
8806 {
8807 case KEY_ESC:
8808 case KEY_ENTER:
8809 goto finished;
8810 }
8811 object_message(dialogs+1, MSG_XCHAR, k);
8812 Flags=cFLAGS;
8813 }
8814
8815 MouseSprite::set(ZQM_FLAG_0+(shift?0:Flag%16));
8816
8817 refresh(rALL | rCLEAR | rNOCURSOR);
8818 custom_vsync();
8819 }
8820
8821 finished:
8822 Flags=of;
8823 placing_flags = false;
8824 MouseSprite::set(ZQM_NORMAL);
8825 refresh(rMAP+rMENU);
8826
8827 while(gui_mouse_b())
8828 {
8829 /* do nothing */
8830 rest(1);
8831 }
8832 }
8833
8834 // Drag FFCs around
8835 static void moveffc(int i, int cx, int cy)
8836 {
8837 mapscr* scr = active_visible_screen->scr;
8838 int screen = active_visible_screen->screen;
8839
8840 int32_t ffx = vbound(scr->ffcs[i].x.getFloor(),0,240);
8841 int32_t ffy = vbound(scr->ffcs[i].y.getFloor(),0,160);
8842 int32_t offx = ffx, offy = ffy;
8843 showxypos_ffc = i;
8844 doxypos((byte&)ffx,(byte&)ffy,15,SNAP_HALF,SNAP_NONE,true,0,0,(scr->ffTileWidth(i)*16),(scr->ffTileHeight(i)*16));
8845 if(ffx > 240) ffx = 240;
8846 if(ffy > 160) ffy = 160;
8847 if((ffx != offx) || (ffy != offy))
8848 {
8849 auto set_ffc_data = set_ffc_command::create_data(scr->ffcs[i]);
8850 set_ffc_data.x = ffx;
8851 set_ffc_data.y = ffy;
8852 Map.DoSetFFCCommand(Map.getCurrMap(), screen, i, set_ffc_data);
8853 saved = false;
8854 }
8855 }
8856
8857 void set_brush_width(int32_t width);
8858 void set_brush_height(int32_t height);
8859
8860 int32_t set_brush_width_1()
8861 {
8862 set_brush_width(1);
8863 return D_O_K;
8864 }
8865 int32_t set_brush_width_2()
8866 {
8867 set_brush_width(2);
8868 return D_O_K;
8869 }
8870 int32_t set_brush_width_3()
8871 {
8872 set_brush_width(3);
8873 return D_O_K;
8874 }
8875 int32_t set_brush_width_4()
8876 {
8877 set_brush_width(4);
8878 return D_O_K;
8879 }
8880 int32_t set_brush_width_5()
8881 {
8882 set_brush_width(5);
8883 return D_O_K;
8884 }
8885 int32_t set_brush_width_6()
8886 {
8887 set_brush_width(6);
8888 return D_O_K;
8889 }
8890 int32_t set_brush_width_7()
8891 {
8892 set_brush_width(7);
8893 return D_O_K;
8894 }
8895 int32_t set_brush_width_8()
8896 {
8897 set_brush_width(8);
8898 return D_O_K;
8899 }
8900 int32_t set_brush_width_9()
8901 {
8902 set_brush_width(9);
8903 return D_O_K;
8904 }
8905 int32_t set_brush_width_10()
8906 {
8907 set_brush_width(10);
8908 return D_O_K;
8909 }
8910 int32_t set_brush_width_11()
8911 {
8912 set_brush_width(11);
8913 return D_O_K;
8914 }
8915 int32_t set_brush_width_12()
8916 {
8917 set_brush_width(12);
8918 return D_O_K;
8919 }
8920 int32_t set_brush_width_13()
8921 {
8922 set_brush_width(13);
8923 return D_O_K;
8924 }
8925 int32_t set_brush_width_14()
8926 {
8927 set_brush_width(14);
8928 return D_O_K;
8929 }
8930 int32_t set_brush_width_15()
8931 {
8932 set_brush_width(15);
8933 return D_O_K;
8934 }
8935 int32_t set_brush_width_16()
8936 {
8937 set_brush_width(16);
8938 return D_O_K;
8939 }
8940
8941 int32_t set_brush_height_1()
8942 {
8943 set_brush_height(1);
8944 return D_O_K;
8945 }
8946 int32_t set_brush_height_2()
8947 {
8948 set_brush_height(2);
8949 return D_O_K;
8950 }
8951 int32_t set_brush_height_3()
8952 {
8953 set_brush_height(3);
8954 return D_O_K;
8955 }
8956 int32_t set_brush_height_4()
8957 {
8958 set_brush_height(4);
8959 return D_O_K;
8960 }
8961 int32_t set_brush_height_5()
8962 {
8963 set_brush_height(5);
8964 return D_O_K;
8965 }
8966 int32_t set_brush_height_6()
8967 {
8968 set_brush_height(6);
8969 return D_O_K;
8970 }
8971 int32_t set_brush_height_7()
8972 {
8973 set_brush_height(7);
8974 return D_O_K;
8975 }
8976 int32_t set_brush_height_8()
8977 {
8978 set_brush_height(8);
8979 return D_O_K;
8980 }
8981 int32_t set_brush_height_9()
8982 {
8983 set_brush_height(9);
8984 return D_O_K;
8985 }
8986 int32_t set_brush_height_10()
8987 {
8988 set_brush_height(10);
8989 return D_O_K;
8990 }
8991 int32_t set_brush_height_11()
8992 {
8993 set_brush_height(11);
8994 return D_O_K;
8995 }
8996
8997
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu brush_width_menu
8998 204 {
8999
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "1", set_brush_width_1 },
9000
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "2", set_brush_width_2 },
9001
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "3", set_brush_width_3 },
9002
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "4", set_brush_width_4 },
9003
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "5", set_brush_width_5 },
9004
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "6", set_brush_width_6 },
9005
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "7", set_brush_width_7 },
9006
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "8", set_brush_width_8 },
9007
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "9", set_brush_width_9 },
9008
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "10", set_brush_width_10 },
9009
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "11", set_brush_width_11 },
9010
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "12", set_brush_width_12 },
9011
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "13", set_brush_width_13 },
9012
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "14", set_brush_width_14 },
9013
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "15", set_brush_width_15 },
9014
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "16", set_brush_width_16 },
9015 };
9016
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu brush_height_menu
9017 144 {
9018
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "1", set_brush_height_1 },
9019
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "2", set_brush_height_2 },
9020
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "3", set_brush_height_3 },
9021
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "4", set_brush_height_4 },
9022
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "5", set_brush_height_5 },
9023
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "6", set_brush_height_6 },
9024
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "7", set_brush_height_7 },
9025
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "8", set_brush_height_8 },
9026
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "9", set_brush_height_9 },
9027
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "10", set_brush_height_10 },
9028
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "11", set_brush_height_11 },
9029 };
9030
9031 int toggle_autobrush();
9032 int toggle_combobrush();
9033 int toggle_floatbrush();
9034 enum
9035 {
9036 MENUID_BRUSH_AUTOBRUSH,
9037 MENUID_BRUSH_WIDTH,
9038 MENUID_BRUSH_HEIGHT,
9039 MENUID_BRUSH_COMBOBRUSH,
9040 MENUID_BRUSH_FLOATBRUSH,
9041 };
9042
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu brush_menu
9043 72 {
9044
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "AutoBrush", toggle_autobrush, MENUID_BRUSH_AUTOBRUSH },
9045
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Brush Width ", &brush_width_menu, MENUID_BRUSH_WIDTH },
9046
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Brush Height ", &brush_height_menu, MENUID_BRUSH_HEIGHT },
9047
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "ComboBrush", toggle_combobrush, MENUID_BRUSH_COMBOBRUSH },
9048
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "FloatBrush", toggle_floatbrush, MENUID_BRUSH_FLOATBRUSH },
9049 };
9050 int toggle_autobrush()
9051 {
9052 AutoBrush = AutoBrush ? 0 : 1;
9053 BrushWidth = BrushHeight = 1;
9054 brush_menu.select_uid(MENUID_BRUSH_AUTOBRUSH, AutoBrush);
9055 brush_menu.disable_uid(MENUID_BRUSH_WIDTH, AutoBrush);
9056 brush_menu.disable_uid(MENUID_BRUSH_HEIGHT, AutoBrush);
9057 zc_set_config("zquest","autobrush",AutoBrush);
9058 return D_O_K;
9059 }
9060 int toggle_combobrush()
9061 {
9062 ComboBrush = ComboBrush ? 0 : 1;
9063 brush_menu.select_uid(MENUID_BRUSH_COMBOBRUSH, ComboBrush);
9064 zc_set_config("zquest","combo_brush",ComboBrush);
9065 return D_O_K;
9066 }
9067 int toggle_floatbrush()
9068 {
9069 FloatBrush = FloatBrush ? 0 : 1;
9070 brush_menu.select_uid(MENUID_BRUSH_FLOATBRUSH, FloatBrush);
9071 zc_set_config("zquest","float_brush",FloatBrush);
9072 return D_O_K;
9073 }
9074
9075 int32_t set_flood();
9076 int32_t set_fill_4();
9077 int32_t set_fill_8();
9078 int32_t set_fill2_4();
9079 int32_t set_fill2_8();
9080
9081 // Sets every combo.
9082 void flood()
9083 {
9084 ComboPosition pos = get_mapscreen_mouse_combo_pos();
9085 mapscr* scr = Map.ScrMakeValid(pos, CurrentLayer);
9086 if (!scr || !scr->is_valid())
9087 return;
9088
9089 saved=false;
9090
9091 bool include_combos = !(key[KEY_LSHIFT]||key[KEY_RSHIFT]);
9092
9093 int num_combos_width = 16 * Map.getViewSize();
9094 int num_combos_height = 11 * Map.getViewSize();
9095
9096 Map.StartListCommand();
9097 for (int x = 0; x < num_combos_width; x++)
9098 {
9099 for (int y = 0; y < num_combos_height; y++)
9100 {
9101 ComboPosition pos = {x, y};
9102 mapscr* scr = Map.Scr(pos, CurrentLayer);
9103 if (!scr || !scr->is_valid())
9104 continue;
9105
9106 if (draw_mode == dm_auto)
9107 draw_autocombo(pos, gui_mouse_b() & 2);
9108 else
9109 Map.DoSetComboCommand(pos, include_combos ? Combo : -1, CSet);
9110 }
9111 }
9112 Map.FinishListCommand();
9113
9114 refresh(rMAP+rSCRMAP);
9115 }
9116 void flood_flag()
9117 {
9118 ComboPosition pos = get_mapscreen_mouse_combo_pos();
9119 mapscr* scr = Map.ScrMakeValid(pos, CurrentLayer);
9120 if (!scr || !scr->is_valid())
9121 return;
9122
9123 saved=false;
9124
9125 int num_combos_width = 16 * Map.getViewSize();
9126 int num_combos_height = 11 * Map.getViewSize();
9127
9128 Map.StartListCommand();
9129 for (int x = 0; x < num_combos_width; x++)
9130 {
9131 for (int y = 0; y < num_combos_height; y++)
9132 {
9133 ComboPosition pos = {x, y};
9134 mapscr* scr = Map.Scr(pos, CurrentLayer);
9135 if (!scr || !scr->is_valid())
9136 continue;
9137
9138 Map.DoSetFlagCommand(pos, Flag);
9139 }
9140 }
9141 Map.FinishListCommand();
9142
9143 refresh(rMAP+rSCRMAP);
9144 }
9145
9146 void fill_4()
9147 {
9148 ComboPosition pos = get_mapscreen_mouse_combo_pos();
9149 mapscr* scr = Map.ScrMakeValid(pos, CurrentLayer);
9150 if (!scr)
9151 return;
9152
9153 int c = pos.truncate();
9154 if (draw_mode == dm_cpool || draw_mode == dm_auto
9155 || (scr->cset[c]!=CSet || (scr->data[c]!=Combo && !(key[KEY_LSHIFT]||key[KEY_RSHIFT]))))
9156 {
9157 saved=false;
9158
9159 Map.StartListCommand();
9160 if (draw_mode == dm_auto && (combo_autos[combo_auto_pos].getType() == AUTOCOMBO_FENCE ||
9161 combo_autos[combo_auto_pos].getType() == AUTOCOMBO_Z4))
9162 {
9163 draw_autocombo_command(pos);
9164 }
9165 else
9166 {
9167 bool allow_diagonal = false;
9168 fill(scr->data[c], scr->cset[c], pos, allow_diagonal, (key[KEY_LSHIFT] || key[KEY_RSHIFT]));
9169 }
9170 Map.FinishListCommand();
9171 refresh(rMAP+rSCRMAP);
9172 }
9173 }
9174 void fill_4_flag()
9175 {
9176 ComboPosition pos = get_mapscreen_mouse_combo_pos();
9177 mapscr* scr = Map.ScrMakeValid(pos, CurrentLayer);
9178 if (!scr)
9179 return;
9180
9181 int flag = scr->sflag[pos.truncate()];
9182 if (flag != Flag)
9183 {
9184 saved=false;
9185
9186 Map.StartListCommand();
9187 bool allow_diagonal = false;
9188 fill_flag(flag, pos, allow_diagonal);
9189 Map.FinishListCommand();
9190 refresh(rMAP+rSCRMAP);
9191 }
9192 }
9193 void fill_8()
9194 {
9195 ComboPosition pos = get_mapscreen_mouse_combo_pos();
9196 mapscr* scr = Map.ScrMakeValid(pos, CurrentLayer);
9197 if (!scr)
9198 return;
9199
9200 int c = pos.truncate();
9201 if (draw_mode == dm_cpool || draw_mode == dm_auto
9202 || (scr->cset[c] != CSet ||
9203 (scr->data[c] != Combo &&
9204 !(key[KEY_LSHIFT]||key[KEY_RSHIFT]))))
9205 {
9206 saved=false;
9207
9208 Map.StartListCommand();
9209 bool allow_diagonal = true;
9210 fill(scr->data[c], scr->cset[c], pos, allow_diagonal, (key[KEY_LSHIFT]||key[KEY_RSHIFT]));
9211 Map.FinishListCommand();
9212
9213 refresh(rMAP+rSCRMAP);
9214 }
9215 }
9216 void fill_8_flag()
9217 {
9218 ComboPosition pos = get_mapscreen_mouse_combo_pos();
9219 mapscr* scr = Map.ScrMakeValid(pos, CurrentLayer);
9220 if (!scr)
9221 return;
9222
9223 int flag = scr->sflag[pos.truncate()];
9224 if (flag != Flag)
9225 {
9226 saved=false;
9227
9228 Map.StartListCommand();
9229 bool allow_diagonal = true;
9230 fill_flag(flag, pos, allow_diagonal);
9231 Map.FinishListCommand();
9232 refresh(rMAP+rSCRMAP);
9233 }
9234 }
9235
9236 void fill2_4()
9237 {
9238 ComboPosition pos = get_mapscreen_mouse_combo_pos();
9239 mapscr* scr = Map.ScrMakeValid(pos, CurrentLayer);
9240 if (!scr)
9241 return;
9242
9243 saved=false;
9244
9245 Map.StartListCommand();
9246 fill2(Combo, CSet, pos, 255, 0, (key[KEY_LSHIFT]||key[KEY_RSHIFT]));
9247 Map.FinishListCommand();
9248 refresh(rMAP+rSCRMAP);
9249 }
9250
9251 void fill2_8()
9252 {
9253 ComboPosition pos = get_mapscreen_mouse_combo_pos();
9254 mapscr* scr = Map.ScrMakeValid(pos, CurrentLayer);
9255 if (!scr)
9256 return;
9257
9258 saved=false;
9259
9260 Map.StartListCommand();
9261 fill2(Combo, CSet, pos, 255, 1, (key[KEY_LSHIFT]||key[KEY_RSHIFT]));
9262 Map.FinishListCommand();
9263
9264 refresh(rMAP+rSCRMAP);
9265 }
9266
9267
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu fill_menu
9268 72 {
9269
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Flood", set_flood, 0 },
9270
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Fill (4-way)", set_fill_4, 1 },
9271
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Fill (8-way)", set_fill_8, 2 },
9272
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Fill2 (4-way)", set_fill2_4, 3 },
9273
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Fill2 (8-way)", set_fill2_8, 4 },
9274 };
9275 void set_filltype(int ty)
9276 {
9277 fill_type = ty;
9278 fill_menu.select_only_uid(ty);
9279 }
9280
9281 int32_t set_flood()
9282 {
9283 set_filltype(0);
9284 return D_O_K;
9285 }
9286
9287 int32_t set_fill_4()
9288 {
9289 set_filltype(1);
9290 return D_O_K;
9291 }
9292
9293 int32_t set_fill_8()
9294 {
9295 set_filltype(2);
9296 return D_O_K;
9297 }
9298
9299 int32_t set_fill2_4()
9300 {
9301 set_filltype(3);
9302 return D_O_K;
9303 }
9304
9305 int32_t set_fill2_8()
9306 {
9307 set_filltype(4);
9308 return D_O_K;
9309 }
9310
9311 int32_t draw_block_1_2()
9312 {
9313 draw_block(mouse_combo_pos,1,2);
9314 return D_O_K;
9315 }
9316
9317 int32_t draw_block_2_1()
9318 {
9319 draw_block(mouse_combo_pos,2,1);
9320 return D_O_K;
9321 }
9322
9323 int32_t draw_block_2_2()
9324 {
9325 draw_block(mouse_combo_pos,2,2);
9326 return D_O_K;
9327 }
9328
9329 int32_t draw_block_2_3()
9330 {
9331 draw_block(mouse_combo_pos,2,3);
9332 return D_O_K;
9333 }
9334
9335 int32_t draw_block_3_2()
9336 {
9337 draw_block(mouse_combo_pos,3,2);
9338 return D_O_K;
9339 }
9340
9341 int32_t draw_block_3_3()
9342 {
9343 draw_block(mouse_combo_pos,3,3);
9344 return D_O_K;
9345 }
9346
9347 int32_t draw_block_4_2()
9348 {
9349 draw_block(mouse_combo_pos,4,2);
9350 return D_O_K;
9351 }
9352
9353 int32_t draw_block_4_4()
9354 {
9355 draw_block(mouse_combo_pos,4,4);
9356 return D_O_K;
9357 }
9358
9359
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu draw_block_menu
9360 108 {
9361
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "1x2", draw_block_1_2 },
9362
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "2x1", draw_block_2_1 },
9363
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "2x2", draw_block_2_2 },
9364
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "2x3", draw_block_2_3 },
9365
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "3x2", draw_block_3_2 },
9366
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "3x3", draw_block_3_3 },
9367
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "4x2", draw_block_4_2 },
9368
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "4x4", draw_block_4_4 },
9369 };
9370
9371
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu paste_screen_menu
9372 60 {
9373
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Paste", onPaste },
9374
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Paste All", onPasteAll },
9375
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Paste to All", onPasteToAll },
9376
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Paste All to All", onPasteAllToAll },
9377 };
9378
9379 int32_t scrollto_cmb(int32_t cid)
9380 {
9381 auto& sqr = combolist[current_combolist];
9382 int32_t res = vbound(cid-(sqr.w*sqr.h/2),0,MAXCOMBOS-(sqr.w*sqr.h));
9383 res -= res%sqr.w;
9384 return res;
9385 }
9386 int32_t scrollto_alias(int32_t alid)
9387 {
9388 auto& sqr = comboaliaslist[current_comboalist];
9389 int32_t res = vbound(alid-(sqr.w*sqr.h/2),0,MAXCOMBOALIASES-(sqr.w*sqr.h));
9390 res -= res%sqr.w;
9391 return res;
9392 }
9393
9394 int32_t scrollto_cpool(int32_t cpid)
9395 {
9396 auto& sqr = comboaliaslist[current_cpoollist];
9397 int32_t res = vbound(cpid-(sqr.w*sqr.h/2),0,MAXCOMBOPOOLS-(sqr.w*sqr.h));
9398 res -= res%sqr.w;
9399 return res;
9400 }
9401
9402 int32_t scrollto_cauto(int32_t caid)
9403 {
9404 auto& sqr = comboaliaslist[current_cautolist];
9405 int32_t res = vbound(caid - (sqr.w * sqr.h / 2), 0, MAXCOMBOPOOLS - (sqr.w * sqr.h));
9406 res -= res % sqr.w;
9407 return res;
9408 }
9409
9410 void add_favorite_combo_block(int32_t favind, int32_t cid, bool force)
9411 {
9412 int32_t w = vbound(BrushWidth, 1, 4);
9413 int32_t h = vbound(BrushHeight, 1, 7);
9414 for (int32_t xi = 0; xi < w; ++xi)
9415 {
9416 for (int32_t yi = 0; yi < h; ++yi)
9417 {
9418 int32_t cx = cid % 4;
9419 int32_t cy = cid / 4;
9420 int32_t cc = (cy + yi) * 4 + cx + xi;
9421 int32_t fx = favind % FAVORITECOMBO_PER_ROW;
9422 int32_t fy = favind / FAVORITECOMBO_PER_ROW;
9423 int32_t fc = (fy + yi) * FAVORITECOMBO_PER_ROW + fx + xi + FAVORITECOMBO_PER_PAGE * FavoriteComboPage;
9424
9425 if (cx + xi < 4 && cc < MAXCOMBOS && fx + xi < FAVORITECOMBO_PER_ROW && fy + yi < FAVORITECOMBO_PER_COLUMN)
9426 {
9427 if (favorite_combos[fc] < 0 || force)
9428 {
9429 favorite_combo_modes[fc] = dm_normal;
9430 favorite_combos[fc] = cc;
9431 }
9432 }
9433 }
9434 }
9435 }
9436
9437 void onRCSelectCombo(int32_t c)
9438 {
9439 int32_t drawmap, drawscr;
9440
9441 if(CurrentLayer==0)
9442 {
9443 drawmap=Map.getCurrMap();
9444 drawscr=Map.getCurrScr();
9445 }
9446 else
9447 {
9448 drawmap=Map.CurrScr()->layermap[CurrentLayer-1]-1;
9449 drawscr=Map.CurrScr()->layerscreen[CurrentLayer-1];
9450 }
9451 mapscr* draw_mapscr = Map.AbsoluteScr(drawmap, drawscr);
9452 if(!draw_mapscr) return;
9453
9454 Combo=draw_mapscr->data[c];
9455 if(AutoBrush)
9456 BrushWidth = BrushHeight = 1;
9457 }
9458
9459 void onRCScrollToombo(int32_t c)
9460 {
9461 int32_t drawmap, drawscr;
9462
9463 if(CurrentLayer==0)
9464 {
9465 drawmap=Map.getCurrMap();
9466 drawscr=Map.getCurrScr();
9467 }
9468 else
9469 {
9470 drawmap=Map.CurrScr()->layermap[CurrentLayer-1]-1;
9471 drawscr=Map.CurrScr()->layerscreen[CurrentLayer-1];
9472 }
9473 mapscr* draw_mapscr = Map.AbsoluteScr(drawmap, drawscr);
9474 if(!draw_mapscr) return;
9475
9476 auto& sqr = combolist[current_combolist];
9477 First[current_combolist]=scrollto_cmb(draw_mapscr->data[c]);
9478 }
9479
9480 enum
9481 {
9482 MENUID_RCSCREEN_PASTE,
9483 MENUID_RCSCREEN_ADVPASTE,
9484 MENUID_RCSCREEN_SPECPASTE,
9485 };
9486
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu rc_menu_screen
9487 60 {
9488
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Copy Screen", onCopy },
9489
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Paste Screen", &paste_screen_menu, MENUID_RCSCREEN_PASTE },
9490
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "...Advanced Paste", &paste_menu, MENUID_RCSCREEN_ADVPASTE },
9491
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "...Special Paste", &paste_item_menu, MENUID_RCSCREEN_SPECPASTE },
9492 };
9493
9494 void call_options_dlg();
9495 int32_t onOptions()
9496 {
9497 call_options_dlg();
9498 brush_menu.select_uid(MENUID_BRUSH_AUTOBRUSH, AutoBrush);
9499 brush_menu.disable_uid(MENUID_BRUSH_WIDTH, AutoBrush);
9500 brush_menu.disable_uid(MENUID_BRUSH_HEIGHT, AutoBrush);
9501 brush_menu.select_uid(MENUID_BRUSH_FLOATBRUSH, FloatBrush);
9502 brush_menu.select_uid(MENUID_BRUSH_COMBOBRUSH, ComboBrush);
9503 return D_O_K;
9504 }
9505
9506 void follow_twarp(int warpindex)
9507 {
9508 if(warpindex >= 4)
9509 {
9510 InfoDialog("Random Tile Warp",
9511 "This is a random tile warp combo, so it chooses"
9512 " randomly between the screen's four Tile Warps.").show();
9513 warpindex=zc_oldrand()&3;
9514 }
9515
9516 int32_t tm = Map.getCurrMap();
9517 int32_t ts = Map.getCurrScr();
9518 int32_t wt = Map.CurrScr()->tilewarptype[warpindex];
9519
9520 if(wt==wtCAVE || wt==wtNOWARP)
9521 {
9522 char buf[56];
9523 InfoDialog(warptype_string[wt],fmt::format("This screen's Tile Warp {} is set to {}, so it doesn't lead to another screen.",'A'+warpindex,warptype_string[wt]));
9524 return;
9525 }
9526
9527 Map.dowarp(0,warpindex);
9528
9529 if(ts!=Map.getCurrScr() || tm!=Map.getCurrMap())
9530 {
9531 FlashWarpSquare = (TheMaps[tm*MAPSCRS+ts].warpreturnc>>(warpindex*2))&3;
9532 FlashWarpClk = 32;
9533 }
9534 }
9535 void edit_twarp(int warpindex)
9536 {
9537 if(warpindex>=4)
9538 {
9539 InfoDialog("Random Tile Warp",
9540 "This is a random tile warp combo, so it chooses"
9541 " randomly between the screen's four Tile Warps.").show();
9542 warpindex=zc_oldrand()&3;
9543 }
9544
9545 if(warpindex > -1 && warpindex < 4)
9546 onTileWarpIndex(warpindex);
9547 }
9548
9549 int toggle_linked_scrolling()
9550 {
9551 LinkedScroll = LinkedScroll ? 0 : 1;
9552 zc_set_config("zquest","linked_comboscroll",LinkedScroll);
9553 return D_O_K;
9554 }
9555 void on_scroll_cpane()
9556 {
9557 switch (draw_mode)
9558 {
9559 case dm_alias:
9560 combo_alistpos[current_comboalist] = scrollto_alias(combo_apos);
9561 break;
9562 case dm_cpool:
9563 combo_pool_listpos[current_cpoollist] = scrollto_cpool(combo_pool_pos);
9564 break;
9565 case dm_auto:
9566 combo_auto_listpos[current_cautolist] = scrollto_cauto(combo_auto_pos);
9567 break;
9568 default:
9569 First[current_combolist] = scrollto_cmb(Combo);
9570 break;
9571 }
9572 }
9573 void on_edit_cpane()
9574 {
9575 switch (draw_mode)
9576 {
9577 case dm_alias:
9578 onEditComboAlias();
9579 break;
9580 case dm_cpool:
9581 onEditComboPool();
9582 break;
9583 case dm_auto:
9584 onEditAutoCombo();
9585 break;
9586 default:
9587 reset_combo_animations();
9588 reset_combo_animations2();
9589 edit_combo(Combo, true, CSet);
9590 setup_combo_animations();
9591 setup_combo_animations2();
9592 break;
9593 }
9594 }
9595 void on_cpane_page()
9596 {
9597 switch(draw_mode)
9598 {
9599 case dm_normal:
9600 combo_screen(Combo>>8,Combo);
9601 break;
9602 case dm_alias:
9603 call_alias_pages(combo_apos);
9604 break;
9605 case dm_auto:
9606 call_autoc_pages(combo_auto_pos);
9607 break;
9608 case dm_cpool:
9609 call_cpool_pages(combo_pool_pos);
9610 break;
9611 }
9612 }
9613 void open_cpane_tilepage()
9614 {
9615 onGotoTiles(combobuf[Combo].o_tile);
9616 }
9617 static int _clicked_fav = 0;
9618 void fav_rc_remove()
9619 {
9620 favorite_combo_modes[_clicked_fav] = dm_normal;
9621 favorite_combos[_clicked_fav] = -1;
9622 saved = false;
9623 }
9624 void popup_favorites_rc(int f, int x, int y)
9625 {
9626 _clicked_fav = f;
9627 string type;
9628 switch (draw_mode)
9629 {
9630 case dm_alias:
9631 type = "Alias";
9632 break;
9633 case dm_cpool:
9634 type = "Pool";
9635 break;
9636 case dm_auto:
9637 type = "Autocombo";
9638 break;
9639 case dm_normal:
9640 type = "Combo";
9641 break;
9642 default: return;
9643 }
9644 NewMenu rcmenu
9645 {
9646 { fmt::format("Scroll to {}", type), on_scroll_cpane },
9647 { fmt::format("Edit {}", type), on_edit_cpane },
9648 { fmt::format("Open {} Page", type), on_cpane_page },
9649 { fmt::format("Remove Fav {}", type), fav_rc_remove },
9650 };
9651 switch (draw_mode)
9652 {
9653 case dm_normal:
9654 rcmenu.add({
9655 {},
9656 { "Open Tile Page", open_cpane_tilepage },
9657 });
9658 break;
9659 }
9660 rcmenu.pop(x, y);
9661 }
9662 void popup_cpane_rc(int x, int y)
9663 {
9664 string type;
9665 switch (draw_mode)
9666 {
9667 case dm_alias:
9668 type = "Alias";
9669 break;
9670 case dm_cpool:
9671 type = "Pool";
9672 break;
9673 case dm_auto:
9674 type = "Autocombo";
9675 break;
9676 case dm_normal:
9677 type = "Combo";
9678 break;
9679 default: return;
9680 }
9681 NewMenu rcmenu;
9682 switch(draw_mode)
9683 {
9684 case dm_normal:
9685 rcmenu.add({
9686 { fmt::format("Edit {}", type), on_edit_cpane },
9687 { fmt::format("Open {} Page", type), on_cpane_page },
9688 { "Open Tile Page", open_cpane_tilepage },
9689 { "Combo Locations", onComboLocationReport },
9690 {},
9691 { "Scroll to Page...", onGotoPage },
9692 { "Linked Scrolling", toggle_linked_scrolling, nullopt, LinkedScroll ? MFL_SEL : 0 },
9693 });
9694 break;
9695 case dm_alias:
9696 case dm_cpool:
9697 case dm_auto:
9698 rcmenu.add({
9699 { fmt::format("Edit {}", type), on_edit_cpane },
9700 { fmt::format("Open {} Page", type), on_cpane_page },
9701 {},
9702 { "Scroll to Page...", onGotoPage },
9703 { "Linked Scrolling", toggle_linked_scrolling, nullopt, LinkedScroll ? MFL_SEL : 0 },
9704 });
9705 break;
9706 }
9707 rcmenu.pop(x, y);
9708 }
9709
9710 void set_brush_width(int32_t width)
9711 {
9712 BrushWidth = width;
9713 for(int q = 0; q < brush_width_menu.size(); ++q)
9714 brush_width_menu.at(q)->select(q==BrushWidth-1);
9715 refresh(rALL);
9716 }
9717
9718 void set_brush_height(int32_t height)
9719 {
9720 BrushHeight = height;
9721 for(int q = 0; q < brush_height_menu.size(); ++q)
9722 brush_height_menu.at(q)->select(q==BrushHeight-1);
9723 refresh(rALL);
9724 }
9725
9726 1 void restore_mouse()
9727 {
9728 1 ComboBrushPause=1;
9729 1 MouseSprite::set(ZQM_NORMAL);
9730 1 }
9731
9732 static int32_t comboa_cnt=0;
9733 static int32_t combop_cnt=0;
9734 static int32_t layer_cnt=0;
9735
9736 static char paste_ffc_menu_text[21];
9737 static char paste_ffc_menu_text2[21];
9738 static char follow_warp_menu_text[21];
9739 static char follow_warp_menu_text2[21];
9740
9741 static int fake_mouse_b(){return 0;}
9742 static int (*mouseb_proc)();
9743 static bool killed_mouse = false;
9744 void zq_killmouse()
9745 {
9746 if(killed_mouse) return;
9747 mouseb_proc = gui_mouse_b;
9748 gui_mouse_b = fake_mouse_b;
9749 killed_mouse = true;
9750 }
9751 void zq_restoremouse()
9752 {
9753 if(!killed_mouse) return;
9754 gui_mouse_b = mouseb_proc;
9755 killed_mouse = false;
9756 }
9757
9758
9759 void domouse()
9760 {
9761 static int mouse_down = 0;
9762 static int32_t scrolldelay = 0;
9763 auto mousexy = zc_get_mouse();
9764 auto x = mousexy.first;
9765 auto y = mousexy.second;
9766 double startx=mapscreen_x+(showedges?(16*mapscreen_single_scale):0);
9767 double starty=mapscreen_y+(showedges?(16*mapscreen_single_scale):0);
9768 int32_t startxint=mapscreen_x+(showedges?int32_t(16*mapscreen_single_scale):0);
9769 int32_t startyint=mapscreen_y+(showedges?int32_t(16*mapscreen_single_scale):0);
9770 int32_t cx=(x-startx)/(16*mapscreen_single_scale);
9771 int32_t cy=(y-starty)/(16*mapscreen_single_scale);
9772 ComboPosition combo_pos = {cx, cy};
9773
9774 if (draw_mode == dm_auto)
9775 {
9776 if (combo_pos != mouse_combo_pos)
9777 combobrushoverride = get_autocombo_floating_cid(combo_pos, false);
9778 }
9779 else
9780 combobrushoverride = -1;
9781
9782 mouse_combo_pos = combo_pos;
9783 update_combobrush();
9784
9785 ++scrolldelay;
9786
9787 bool x_on_list = false;
9788 for(auto q = 0; q < num_combo_cols; ++q)
9789 {
9790 if((x>=combolist[q].x) && (x<combolist[q].x+(combolist[q].xscale*combolist[q].w)))
9791 {
9792 x_on_list = true;
9793 break;
9794 }
9795 }
9796 if(MouseScroll && x_on_list && (key[KEY_LSHIFT] || key[KEY_RSHIFT] || (scrolldelay&3)==0))
9797 {
9798 int32_t test_list=0;
9799
9800 for(test_list=0; test_list<num_combo_cols; ++test_list)
9801 {
9802 if((x>=combolist[test_list].x) && (x<combolist[test_list].x+(combolist[test_list].xscale*combolist[test_list].w)))
9803 {
9804 break;
9805 }
9806 }
9807
9808 if(test_list<num_combo_cols)
9809 {
9810 if(y>=combolist[test_list].y-mouse_scroll_h && y<=combolist[test_list].y && First[test_list])
9811 {
9812 if((CHECK_CTRL_CMD)&&(key[KEY_ALT] || key[KEY_ALTGR]))
9813 {
9814 First[test_list]=0;
9815 }
9816 else if(CHECK_CTRL_CMD)
9817 {
9818 First[test_list]-=zc_min(First[test_list],256);
9819 }
9820 else if(key[KEY_ALT] || key[KEY_ALTGR])
9821 {
9822 First[test_list]-=zc_min(First[test_list],(combolist[test_list].w*combolist[test_list].h));
9823 }
9824 else
9825 {
9826 First[test_list]-=zc_min(First[test_list],combolist[test_list].w);
9827 }
9828 }
9829
9830 if(y>=combolist[test_list].y+(combolist[test_list].h*combolist[test_list].yscale)-1 && y<combolist[test_list].y+(combolist[test_list].h*combolist[test_list].yscale)+mouse_scroll_h-1 && First[test_list]<(MAXCOMBOS-(combolist[test_list].w*combolist[test_list].h)))
9831 {
9832 int32_t offset = combolist[test_list].w*combolist[test_list].h;
9833
9834 if((CHECK_CTRL_CMD)&&(key[KEY_ALT] || key[KEY_ALTGR]))
9835 {
9836 First[test_list]=MAXCOMBOS-offset;
9837 }
9838 else if(CHECK_CTRL_CMD)
9839 {
9840 First[test_list] = zc_min(MAXCOMBOS-offset, First[test_list]+256);
9841 }
9842 else if(key[KEY_ALT] || key[KEY_ALTGR])
9843 {
9844 First[test_list] = zc_min(MAXCOMBOS-offset, First[test_list]+ offset);
9845 }
9846 else
9847 {
9848 First[test_list] = zc_min(MAXCOMBOS - offset, First[test_list] + combolist[test_list].w);
9849 }
9850 }
9851 }
9852 }
9853
9854 // The screen for this combo_pos, layer 0. Used to access ffcs.
9855 mapscr* scr = Map.Scr(combo_pos);
9856 // The screen for this combo_pos at the CurrentLayer. Could be same as scr.
9857 mapscr* draw_mapscr = scr && CurrentLayer ? Map.Scr(combo_pos, CurrentLayer) : scr;
9858 int c = combo_pos.truncate();
9859 set_active_visible_screen(scr);
9860
9861 //-------------
9862 //tooltip stuff
9863 //-------------
9864 if (active_visible_screen && isinRect(x,y,startxint,startyint,startxint+(256*mapscreen_screenunit_scale)-1,startyint+(176*mapscreen_screenunit_scale)-1))
9865 {
9866 static int mapscr_tooltip_id = ttip_register_id();
9867 bool did_ffttip = false;
9868 int num_ffcs = scr->numFFC();
9869 for(int32_t i=num_ffcs-1; i>=0; i--)
9870 if(scr->ffcs[i].data !=0 && (scr->ffcs[i].layer >= CurrentLayer || (scr->ffcs[i].flags&ffc_overlay)))
9871 {
9872 int32_t ffx = scr->ffcs[i].x.getFloor() + active_visible_screen->dx * 256;
9873 int32_t ffy = scr->ffcs[i].y.getFloor() + active_visible_screen->dy * 176;
9874 int32_t ffw = scr->ffTileWidth(i)*16;
9875 int32_t ffh = scr->ffTileHeight(i)*16;
9876 int32_t cx2 = (x-startxint)/mapscreen_single_scale;
9877 int32_t cy2 = (y-startyint)/mapscreen_single_scale;
9878
9879 if(cx2 >= ffx && cx2 < ffx+ffw && cy2 >= ffy && cy2 < ffy+ffh)
9880 {
9881 // FFC tooltip
9882 if(tooltip_current_ffc != i)
9883 {
9884 clear_tooltip();
9885 }
9886
9887 tooltip_current_ffc = i;
9888 char msg[1024] = {0};
9889 auto& ff = scr->ffcs[i];
9890 sprintf(msg,"FFC: %d Combo: %d\nCSet: %d Type: %s\nScript: %s",
9891 i+1, ff.data,ff.data,
9892 combo_class_buf[combobuf[ff.data].type].name,
9893 (ff.script<=0 ? "(None)" : ffcmap[ff.script-1].scriptname.substr(0,400).c_str()));
9894 ttip_install(mapscr_tooltip_id, msg, startxint+(ffx*mapscreen_single_scale), startyint+(ffy*mapscreen_single_scale), ffw*mapscreen_single_scale, ffh*mapscreen_single_scale, x, y);
9895 did_ffttip = true;
9896 break;
9897 }
9898 }
9899 if(!did_ffttip)
9900 {
9901 if(unsigned(c) < 176 && draw_mapscr && !gui_mouse_b())
9902 {
9903 int cid = draw_mapscr->data[c];
9904 newcombo const& cmb = combobuf[cid];
9905 std::ostringstream oss;
9906 int cs = draw_mapscr->cset[c];
9907 int sflag = draw_mapscr->sflag[c];
9908 oss << "Pos: " << c
9909 << "\nCombo: " << cid
9910 << "\nCSet: " << cs;
9911 if(sflag || cmb.flag)
9912 oss << "\nFlags: " << sflag << ", " << (int)cmb.flag;
9913 if(cmb.type)
9914 oss << "\nCombo type: " << combo_class_buf[cmb.type].name;
9915 if(cmb.label[0])
9916 oss << "\nLabel: " << cmb.label;
9917 ttip_install(mapscr_tooltip_id, oss.str().c_str(), startxint+(cx*16*mapscreen_single_scale), startyint+(cy*16*mapscreen_single_scale), 16*mapscreen_single_scale, 16*mapscreen_single_scale, x, y);
9918 }
9919 }
9920 }
9921
9922 {
9923 size_and_pos* squares[4] = {&itemsqr_pos,&stairsqr_pos,&warparrival_pos,&flagsqr_pos};
9924 for(int32_t j=0; j<4; j++)
9925 {
9926 auto& square = *squares[j];
9927 if(square.rect(x,y))
9928 {
9929 char msg[160];
9930 sprintf(msg,
9931 j==0 ? "Item Location" :
9932 j==1 ? "Stairs Secret\nTriggered when a Trigger Push Block is pushed." :
9933 j==2 ? "Arrival Square\nPlayer's location when they begin/resume the game." :
9934 "Combo Flags");
9935 update_tooltip(x,y,square,msg);
9936 }
9937 }
9938
9939 // Warp Returns
9940 for(int32_t j=0; j<4; j++)
9941 {
9942 size_and_pos& wret = warpret_pos[j];
9943 if(wret.rect(x,y))
9944 {
9945 char msg[160];
9946 sprintf(msg,"Warp Return Square %c\nPlayer's destination after warping to this screen.",(char)('A'+j));
9947 update_tooltip(x,y,wret,msg);
9948 }
9949 }
9950
9951 // Enemies
9952 if(enemy_prev_pos.rect(x,y))
9953 {
9954 char msg[160];
9955 sprintf(msg,"Enemies that appear on this screen.");
9956 update_tooltip(x,y,enemy_prev_pos,msg);
9957 }
9958
9959 int32_t cmd = commands_list.rectind(x,y);
9960 if(cmd > -1)
9961 {
9962 update_tooltip(x,y,commands_list.subsquare(cmd),
9963 fmt::format("Fav Command {}: {}\n{}", cmd,
9964 get_hotkey_name(favorite_commands[cmd]),
9965 get_hotkey_helptext(favorite_commands[cmd])).c_str());
9966 }
9967 }
9968
9969 if(draw_mode==dm_alias)
9970 {
9971 for(int32_t j=0; j<num_combo_cols; ++j)
9972 {
9973 auto& sqr = comboaliaslist[j];
9974 auto ind = sqr.rectind(x,y);
9975 if(ind > -1)
9976 {
9977 auto c2=ind+combo_alistpos[j];
9978 char msg[80];
9979 sprintf(msg, "Combo alias %d", c2);
9980 update_tooltip(x,y,sqr.subsquare(ind), msg);
9981 }
9982 }
9983 }
9984 else if(draw_mode==dm_cpool)
9985 {
9986 for(int32_t j=0; j<num_combo_cols; ++j)
9987 {
9988 auto& sqr = comboaliaslist[j];
9989 auto ind = sqr.rectind(x,y);
9990 if(ind > -1)
9991 {
9992 auto c2=ind+combo_pool_listpos[j];
9993 char msg[80];
9994 sprintf(msg, "Combo Pool %d", c2);
9995 update_tooltip(x,y,sqr.subsquare(ind), msg);
9996 }
9997 }
9998 if(cpool_prev_visible && combopool_prevbtn.rect(x,y))
9999 {
10000 if(do_layer_button_reset(combopool_prevbtn.x,combopool_prevbtn.y,
10001 combopool_prevbtn.w,combopool_prevbtn.h,
10002 weighted_cpool ? "Weighted" : "Unweighted",0,true))
10003 {
10004 weighted_cpool = !weighted_cpool;
10005 }
10006 }
10007 }
10008 else if (draw_mode == dm_auto)
10009 {
10010 for (int32_t j = 0; j < num_combo_cols; ++j)
10011 {
10012 auto& sqr = comboaliaslist[j];
10013 auto ind = sqr.rectind(x, y);
10014 if (ind > -1)
10015 {
10016 auto c2 = ind + combo_auto_listpos[j];
10017 char msg[80];
10018 sprintf(msg, "Auto Combo %d", c2);
10019 update_tooltip(x, y, sqr.subsquare(ind), msg);
10020 }
10021 }
10022 }
10023 else
10024 {
10025 if(combo_preview.rect(x,y))
10026 {
10027 auto str = "Combo Colors:\n"+get_combo_colornames(Combo,CSet);
10028 update_tooltip(x,y,combo_preview,str.c_str());
10029 }
10030 else if(comboprev_buf[0] && combo_preview_text1.rect(x,y))
10031 {
10032 update_tooltip(x,y,combo_preview_text1,comboprev_buf);
10033 }
10034 else if(comboprev_buf2[0] && combo_preview_text2.rect(x,y))
10035 {
10036 update_tooltip(x,y,combo_preview_text2,comboprev_buf2);
10037 }
10038 else for(int32_t j=0; j<num_combo_cols; ++j)
10039 {
10040 auto& sqr = combolist[j];
10041 auto ind = sqr.rectind(x,y);
10042 if(ind > -1)
10043 {
10044 int32_t c2=ind+First[j];
10045 std::ostringstream oss;
10046 newcombo const& cmb = combobuf[c2];
10047 oss << "Combo " << c2 << ": " << combo_class_buf[cmb.type].name;
10048 if(cmb.flag != 0)
10049 oss << "\nInherent flag: " << ZI.getMapFlagName(cmb.flag);
10050 if(!cmb.label.empty())
10051 oss << "\nLabel: " << cmb.label;
10052
10053 update_tooltip(x,y,sqr.subsquare(ind), oss.str().c_str());
10054 }
10055 }
10056 }
10057
10058 if (favorites_list.rect(x, y))
10059 {
10060 int32_t f = favorites_list.rectind(x, y);
10061 int32_t row = f / favorites_list.w;
10062 int32_t col = f % favorites_list.w;
10063 f = (row * FAVORITECOMBO_PER_ROW) + col;
10064
10065 auto& sqr = favorites_list.subsquare(col, row);
10066
10067 char buf[180];
10068 if (favorite_combos[f] == -1)
10069 sprintf(buf, "Fav Combo %d\nEmpty", f);
10070 else
10071 {
10072 switch (favorite_combo_modes[f])
10073 {
10074 case dm_alias:
10075 sprintf(buf, "Fav Combo %d\nAlias %d", f, favorite_combos[f]);
10076 break;
10077 case dm_cpool:
10078 sprintf(buf, "Fav Combo %d\nPool %d", f, favorite_combos[f]);
10079 break;
10080 case dm_auto:
10081 sprintf(buf, "Fav Combo %d\nAutocombo %d", f, favorite_combos[f]);
10082 break;
10083 default:
10084 sprintf(buf, "Fav Combo %d\nCombo %d", f, favorite_combos[f]);
10085 }
10086 }
10087 update_tooltip(x, y, sqr, buf);
10088 }
10089
10090 size_and_pos const& real_mini = zoomed_minimap ? real_minimap_zoomed : real_minimap;
10091 auto ind = real_mini.rectind(x,y);
10092 if(ind > -1)
10093 {
10094 char buf[80];
10095 sprintf(buf,"0x%02X (%d)", ind, ind);
10096 ttip_install(minimap_tooltip_id, buf, real_mini.subsquare(ind), real_mini.x+real_mini.tw(), real_mini.y-16);
10097 ttip_set_highlight_thickness(minimap_tooltip_id, zoomed_minimap ? 2 : 1);
10098 // Make sure always above the other tooltip items to the right of the map (even in big map mode).
10099 ttip_set_z_index(minimap_tooltip_id, 100);
10100 ttip_clear_timer();
10101 }
10102 else
10103 {
10104 ttip_uninstall(minimap_tooltip_id);
10105 }
10106
10107 // Mouse clicking stuff
10108 int real_mb = gui_mouse_b();
10109 int mb = real_mb & ~mouse_down; //Only handle clicks that have not been handled already
10110 auto mz = mouse_z;
10111 bool lclick = mb&1;
10112 bool rclick = mb&2;
10113
10114 if (mb && hotkeys_is_active())
10115 {
10116 hotkeys_toggle_display(false);
10117 while (gui_mouse_b())
10118 {
10119 custom_vsync();
10120 }
10121 return;
10122 }
10123
10124 FONT* tfont = font;
10125 if(zoomed_minimap)
10126 {
10127 if((lclick||rclick) && !minimap_zoomed.rect(x,y))
10128 {
10129 // 'Clicked off'
10130 mmap_set_zoom(false);
10131 goto domouse_doneclick;
10132 }
10133 }
10134
10135 if(real_mb==0)
10136 {
10137 mouse_down = 0;
10138 canfill=true;
10139 }
10140 else if(lclick || rclick)
10141 {
10142 //on the minimap
10143 if(real_mini.rect(x,y))
10144 {
10145 if(lclick)
10146 select_scr();
10147 else if(rclick && !(mouse_down&2))
10148 {
10149 mmap_set_zoom(!zoomed_minimap);
10150 }
10151 goto domouse_doneclick;
10152 }
10153
10154 if(zoomed_minimap && minimap_zoomed.rect(x,y))
10155 goto domouse_doneclick; //Eat clicks
10156
10157 //on the map tabs
10158 font = get_custom_font(CFONT_GUI);
10159 for(int32_t btn=0; btn<mappage_count; ++btn)
10160 {
10161 char tbuf[15];
10162 sprintf(tbuf, "%d:%02X", map_page[btn].map+1, map_page[btn].screen);
10163 auto& sqr = map_page_bar[btn];
10164 if(sqr.rect(x,y))
10165 {
10166 if(do_layer_button_reset(sqr.x,sqr.y,sqr.w,sqr.h,tbuf,(btn==current_mappage?D_SELECTED:0)))
10167 {
10168 draw_layer_button(screen, sqr.x,sqr.y,sqr.w,sqr.h,tbuf,D_SELECTED);
10169 map_page[current_mappage].map=Map.getCurrMap();
10170 map_page[current_mappage].screen=Map.getCurrScr();
10171 current_mappage=btn;
10172 Map.setCurrMap(map_page[current_mappage].map);
10173 Map.setCurrScr(map_page[current_mappage].screen);
10174 rebuild_trans_table(); //Woo
10175 }
10176 goto domouse_doneclick;
10177 }
10178 }
10179
10180 if(compactbtn.rect(x,y))
10181 {
10182 if(do_text_button(compactbtn.x, compactbtn.y, compactbtn.w, compactbtn.h, is_compact ? "< Expand" : "> Compact"));
10183 toggle_is_compact();
10184 goto domouse_doneclick;
10185 }
10186
10187 if(!zoom_in_btn_disabled && zoominbtn.rect(x,y))
10188 {
10189 if(do_text_button(zoominbtn.x, zoominbtn.y, zoominbtn.w, zoominbtn.h, "+"))
10190 change_mapscr_zoom(-1);
10191 goto domouse_doneclick;
10192 }
10193
10194 if(!zoom_out_btn_disabled && zoomoutbtn.rect(x,y))
10195 {
10196 if(do_text_button(zoomoutbtn.x, zoomoutbtn.y, zoomoutbtn.w, zoomoutbtn.h, "-"))
10197 change_mapscr_zoom(1);
10198 goto domouse_doneclick;
10199 }
10200
10201 font = get_zc_font(font_lfont_l);
10202 if(combo_merge_btn.rect(x,y))
10203 {
10204 bool merged = is_compact ? compact_merged_combopane : large_merged_combopane;
10205 if(do_text_button(combo_merge_btn.x,combo_merge_btn.y,combo_merge_btn.w,combo_merge_btn.h,merged ? "<|>" : ">|<"))
10206 {
10207 toggle_merged_mode();
10208 }
10209 goto domouse_doneclick;
10210 }
10211
10212 if(favorites_zoombtn.rect(x,y))
10213 {
10214 bool zoomed = is_compact ? compact_zoomed_fav : large_zoomed_fav;
10215 if(do_text_button(favorites_zoombtn.x,favorites_zoombtn.y,favorites_zoombtn.w,favorites_zoombtn.h,zoomed ? "-" : "+"))
10216 {
10217 toggle_favzoom_mode();
10218 }
10219 goto domouse_doneclick;
10220 }
10221 else if(favorites_x.rect(x,y))
10222 {
10223 if(do_text_button(favorites_x.x,favorites_x.y,favorites_x.w,favorites_x.h,"X"))
10224 {
10225 AlertDialog("Clear Favorite Combos",
10226 "Are you sure you want to clear all favorite combos?",
10227 [&](bool ret,bool)
10228 {
10229 if(ret)
10230 {
10231 for(auto q = 0; q < MAXFAVORITECOMBOS; ++q)
10232 {
10233 favorite_combos[q] = -1;
10234 favorite_combo_modes[q] = dm_normal;
10235 }
10236 saved = false;
10237 refresh(rFAVORITES);
10238 }
10239 }).show();
10240 }
10241 goto domouse_doneclick;
10242 }
10243 else if(favorites_infobtn.rect(x,y))
10244 {
10245 if(do_text_button(favorites_infobtn.x,favorites_infobtn.y,favorites_infobtn.w,favorites_infobtn.h,"?"))
10246 {
10247 InfoDialog("Favorite Combos",
10248 "On LClick (empty): Sets clicked favorite to the current combo."
10249 "\nOn LClick: Sets current combo to clicked favorite."
10250 "\nShift+LClick: Sets clicked favorite to current combo."
10251 "\nCtrl+LClick: Clears clicked favorite."
10252 "\nAlt+LClick: Scrolls to clicked favorite."
10253 "\nRClick: Opens context menu."
10254 "\n\nClick the Page buttons (<-/->) to cycle between pages (RClick to jump to a page)"
10255 "\nClick the Zoom button (+/-) to toggle zoom level."
10256 "\nClick the X button to clear all favorite combos.").show();
10257 }
10258 goto domouse_doneclick;
10259 }
10260 else if(favorites_pgleft.rect(x,y))
10261 {
10262 if (do_text_button(favorites_pgleft.x, favorites_pgleft.y, favorites_pgleft.w, favorites_pgleft.h, is_compact ? "<" : "<-"))
10263 {
10264 if (rclick)
10265 {
10266 if(auto val = popup_num_menu(x, y, 1, 9, FavoriteComboPage, [](int p){return fmt::format("Page {}",p);}))
10267 FavoriteComboPage = vbound(*val-1, 0, 8);
10268 }
10269 else
10270 FavoriteComboPage = FavoriteComboPage == 0 ? 8 : --FavoriteComboPage;
10271 reload_zq_gui();
10272 }
10273 goto domouse_doneclick;
10274 }
10275 else if(favorites_pgright.rect(x,y))
10276 {
10277 if (do_text_button(favorites_pgright.x, favorites_pgright.y, favorites_pgright.w, favorites_pgright.h, is_compact ? ">" : "->"))
10278 {
10279 if (rclick)
10280 {
10281 if(auto val = popup_num_menu(x, y, 1, 9, FavoriteComboPage, [](int p){return fmt::format("Page {}",p);}))
10282 FavoriteComboPage = vbound(*val-1, 0, 8);
10283 }
10284 else
10285 FavoriteComboPage = FavoriteComboPage == 8 ? 0 : ++FavoriteComboPage;
10286 reload_zq_gui();
10287 }
10288 goto domouse_doneclick;
10289 }
10290
10291 if(commands_zoombtn.rect(x,y))
10292 {
10293 bool zoomed = is_compact ? compact_zoomed_cmd : large_zoomed_cmd;
10294 if(do_text_button(commands_zoombtn.x,commands_zoombtn.y,commands_zoombtn.w,commands_zoombtn.h,zoomed ? "-" : "+"))
10295 {
10296 toggle_cmdzoom_mode();
10297 }
10298 goto domouse_doneclick;
10299 }
10300 else if(commands_x.rect(x,y))
10301 {
10302 if(do_text_button(commands_x.x,commands_x.y,commands_x.w,commands_x.h,"X"))
10303 {
10304 AlertDialog("Clear Favorite Commands",
10305 "Are you sure you want to clear all favorite commands?",
10306 [&](bool ret,bool)
10307 {
10308 if(ret)
10309 {
10310 char buf[20];
10311 for(auto q = 0; q < MAXFAVORITECOMMANDS; ++q)
10312 {
10313 write_fav_command(q,0);
10314 }
10315 refresh(rFAVORITES);
10316 }
10317 }).show();
10318 }
10319 goto domouse_doneclick;
10320 }
10321 else if(commands_infobtn.rect(x,y))
10322 {
10323 if(do_text_button(commands_infobtn.x,commands_infobtn.y,commands_infobtn.w,commands_infobtn.h,"?"))
10324 {
10325 InfoDialog("Favorite Commands",
10326 "On LClick (empty): Choose a favorite command"
10327 "\nOn LClick: Runs the favorite command"
10328 "\nShift+Click: Choose a favorite command"
10329 "\nRClick: Choose a favorite command"
10330 "\nCtrl+Click: Clears clicked command"
10331 "\nAlt+Click: Shows info on the favorite command"
10332 "\n\nClick the Zoom button (+/-) to toggle zoom level"
10333 "\nClick the X button to clear all favorite commands").show();
10334 }
10335 goto domouse_doneclick;
10336 }
10337 font=tfont;
10338
10339 // On the layer panel
10340 font = get_custom_font(CFONT_GUI);
10341 for(int32_t i=0; i<=6; ++i)
10342 {
10343 int32_t spacing_offs = is_compact ? 2 : 10;
10344 int32_t rx = (i * (layerpanel_buttonwidth+spacing_offs+layerpanel_checkbox_wid)) + layer_panel.x+(is_compact?2:6);
10345 int32_t ry = layer_panel.y;
10346
10347 if ((i == 0 || mapscreen_valid_layers[i - 1]) && isinRect(x,y,rx,ry,rx+layerpanel_buttonwidth-1,ry+layerpanel_buttonheight-1))
10348 {
10349 char tbuf[15];
10350
10351 if (Map.getViewSize() > 1)
10352 {
10353 sprintf(tbuf, "%d", i);
10354 }
10355 else if (i != 0 && mapscreen_valid_layers[i - 1])
10356 {
10357 if (is_compact)
10358 {
10359 sprintf(tbuf, "%s%d %d:%02X",
10360 (i==2 && Map.CurrScr()->flags7&fLAYER2BG) || (i==3 && Map.CurrScr()->flags7&fLAYER3BG) ? "-":"",
10361 i, Map.CurrScr()->layermap[i-1], Map.CurrScr()->layerscreen[i-1]);
10362 }
10363 else
10364 {
10365 sprintf(tbuf, "%s%d (%d:%02X)",
10366 (i==2 && Map.CurrScr()->flags7&fLAYER2BG) || (i==3 && Map.CurrScr()->flags7&fLAYER3BG) ? "-":"",
10367 i, Map.CurrScr()->layermap[i-1], Map.CurrScr()->layerscreen[i-1]);
10368 }
10369 }
10370 else
10371 {
10372 sprintf(tbuf, "%d", i);
10373 }
10374
10375 if(do_text_button(rx, ry, layerpanel_buttonwidth, layerpanel_buttonheight, tbuf))
10376 {
10377 CurrentLayer = i;
10378 goto domouse_doneclick;
10379 }
10380 }
10381
10382 auto cbyofs = (layerpanel_buttonheight-layerpanel_checkbox_hei)/2;
10383 if(isinRect(x,y,rx+layerpanel_buttonwidth+1,ry+cbyofs,rx+layerpanel_buttonwidth+1+layerpanel_checkbox_wid-1,ry+2+layerpanel_checkbox_hei-1))
10384 {
10385 do_checkbox(menu1,rx+layerpanel_buttonwidth+1,ry+cbyofs,layerpanel_checkbox_wid,layerpanel_checkbox_hei,LayerMaskInt[i]);
10386 goto domouse_doneclick;
10387 }
10388 }
10389 font=tfont;
10390
10391 //Uses lclick/rclick separately
10392
10393 //on the map screen
10394 if(isinRect(x,y,startxint,startyint,startxint+(256*mapscreen_screenunit_scale)-1,startyint+(176*mapscreen_screenunit_scale)-1))
10395 {
10396 if (lclick)
10397 {
10398 Map.setCurrScr(Map.getScreenForPosition(combo_pos));
10399 }
10400
10401 if (draw_mode == dm_auto)
10402 {
10403 if (CHECK_CTRL_CMD)
10404 {
10405 if (canfill)
10406 {
10407 switch (fill_type)
10408 {
10409 case 0:
10410 flood();
10411 break;
10412
10413 case 1:
10414 fill_4();
10415 break;
10416
10417 case 2:
10418 fill_8();
10419 break;
10420
10421 case 3:
10422 fill2_4();
10423 break;
10424
10425 case 4:
10426 fill2_8();
10427 break;
10428 }
10429
10430 canfill = false;
10431 }
10432 }
10433 else
10434 draw(key[KEY_LSHIFT] || key[KEY_RSHIFT]);
10435 }
10436 else if (scr && lclick)
10437 {
10438 int32_t cx2 = (x-startxint)/mapscreen_single_scale;
10439 int32_t cy2 = (y-startyint)/mapscreen_single_scale;
10440
10441 // Move items
10442 if (scr->hasitem && active_visible_screen)
10443 {
10444 int32_t ix = scr->itemx + active_visible_screen->dx * 256;
10445 int32_t iy = scr->itemy + active_visible_screen->dy * 176;
10446
10447 if(cx2 >= ix && cx2 < ix+16 && cy2 >= iy && cy2 < iy+16)
10448 doxypos(scr->itemx, scr->itemy, 11, SNAP_HALF, SNAP_NONE, true, 0, 0, 16, 16);
10449 }
10450
10451 // Move FFCs
10452 int num_ffcs = scr->numFFC();
10453 for(int32_t i=num_ffcs-1; i>=0; i--)
10454 if(scr->ffcs[i].data !=0 && (scr->ffcs[i].layer >= CurrentLayer || (scr->ffcs[i].flags&ffc_overlay)))
10455 {
10456 int32_t ffx = scr->ffcs[i].x.getFloor() + active_visible_screen->dx * 256;
10457 int32_t ffy = scr->ffcs[i].y.getFloor() + active_visible_screen->dy * 176;
10458
10459 if(cx2 >= ffx && cx2 < ffx+(scr->ffTileWidth(i)*16) && cy2 >= ffy && cy2 < ffy+(scr->ffTileHeight(i)*16))
10460 {
10461 moveffc(i, cx2, cy2);
10462 break;
10463 }
10464 }
10465
10466 if(key[KEY_ALT]||key[KEY_ALTGR])
10467 {
10468 if (!draw_mapscr) return;
10469
10470 Combo=draw_mapscr->data[c];
10471 if(AutoBrush)
10472 BrushWidth = BrushHeight = 1;
10473 if(key[KEY_LSHIFT]||key[KEY_RSHIFT])
10474 CSet=draw_mapscr->cset[c];
10475 if(CHECK_CTRL_CMD)
10476 First[current_combolist]=scrollto_cmb(draw_mapscr->data[c]);
10477 }
10478 else if(CHECK_CTRL_CMD)
10479 {
10480 if(canfill)
10481 {
10482 switch(fill_type)
10483 {
10484 case 0:
10485 flood();
10486 break;
10487
10488 case 1:
10489 fill_4();
10490 break;
10491
10492 case 2:
10493 fill_8();
10494 break;
10495
10496 case 3:
10497 fill2_4();
10498 break;
10499
10500 case 4:
10501 fill2_8();
10502 break;
10503 }
10504
10505 canfill=false;
10506 }
10507 }
10508 else draw(key[KEY_LSHIFT] || key[KEY_RSHIFT]);
10509 }
10510 else if (scr && rclick)
10511 {
10512 ComboBrushPause=1;
10513 refresh(rMAP);
10514 restore_mouse();
10515 ComboBrushPause=0;
10516
10517 bool clickedffc = false;
10518
10519 // FFC right-click menu
10520 // This loop also serves to find the free ffc with the smallest slot number.
10521 int num_ffcs = scr->numFFC();
10522 uint32_t earliestfreeffc = num_ffcs;
10523 for(int32_t i=num_ffcs-1; i>=0; i--)
10524 {
10525 auto data = scr->ffcs[i].data;
10526 if(data==0)
10527 {
10528 if(i < earliestfreeffc)
10529 earliestfreeffc = i;
10530 continue;
10531 }
10532
10533 if(clickedffc || !(scr->valid&mVALID))
10534 continue;
10535
10536 if(data!=0 && (scr->ffcs[i].layer >= CurrentLayer || (scr->ffcs[i].flags&ffc_overlay)))
10537 {
10538 int32_t ffx = scr->ffcs[i].x.getFloor() + active_visible_screen->dx * 256;
10539 int32_t ffy = scr->ffcs[i].y.getFloor() + active_visible_screen->dy * 176;
10540 int32_t cx2 = (x-startxint)/mapscreen_single_scale;
10541 int32_t cy2 = (y-startyint)/mapscreen_single_scale;
10542
10543 if(cx2 >= ffx && cx2 < ffx+(scr->ffTileWidth(i)*16) && cy2 >= ffy && cy2 < ffy+(scr->ffTileHeight(i)*16))
10544 {
10545 NewMenu rcmenu
10546 {
10547 { "Copy FFC", [&](){Map.CopyFFC(active_visible_screen->screen, i);} },
10548 { "Paste FFC data", [&]()
10549 {
10550 bool didconfirm = false;
10551 AlertDialog("Confirm Paste",
10552 "Really replace the FFC with the data of the copied FFC?",
10553 [&](bool ret,bool)
10554 {
10555 if(ret)
10556 didconfirm = true;
10557 }).show();
10558 if(didconfirm)
10559 {
10560 auto set_ffc_data = Map.getCopyFFCData();
10561 set_ffc_data.x = scr->ffcs[i].x;
10562 set_ffc_data.y = scr->ffcs[i].y;
10563 Map.DoSetFFCCommand(Map.getCurrMap(), active_visible_screen->screen, i, set_ffc_data);
10564 }
10565 }, nullopt, Map.getCopyFFC() < 0 ? MFL_DIS : 0 },
10566 { "Edit FFC", [&](){call_ffc_dialog(i, active_visible_screen->scr, active_visible_screen->screen);} },
10567 { "Clear FFC", [&]()
10568 {
10569 bool didconfirm = false;
10570 AlertDialog("Confirm Clear",
10571 "Really clear this Freeform Combo?",
10572 [&](bool ret,bool)
10573 {
10574 if(ret)
10575 didconfirm = true;
10576 }).show();
10577 if(didconfirm)
10578 {
10579 Map.DoSetFFCCommand(Map.getCurrMap(), active_visible_screen->screen, i, {
10580 .x = 0,
10581 .y = 0,
10582 .vx = 0,
10583 .vy = 0,
10584 .ax = 0,
10585 .ay = 0,
10586 .data = 0,
10587 .cset = 0,
10588 .delay = 0,
10589 .link = 0,
10590 .script = 0,
10591 .tw = 1,
10592 .th = 1,
10593 .ew = 16,
10594 .eh = 16,
10595 .flags = ffc_none,
10596 .initd = 0,
10597 });
10598 saved = false;
10599 }
10600 } },
10601 { "Snap to Grid", [&]()
10602 {
10603 int oldffx = scr->ffcs[i].x.getInt();
10604 int oldffy = scr->ffcs[i].y.getInt();
10605 int pos = COMBOPOS(oldffx,oldffy);
10606 int newffy = COMBOY(pos);
10607 int newffx = COMBOX(pos);
10608
10609 auto set_ffc_data = set_ffc_command::create_data(scr->ffcs[i]);
10610 set_ffc_data.x = newffx;
10611 set_ffc_data.y = newffy;
10612 Map.DoSetFFCCommand(Map.getCurrMap(), active_visible_screen->screen, i, set_ffc_data);
10613
10614 saved = false;
10615 } },
10616 };
10617 rcmenu.pop(x, y);
10618 clickedffc = true;
10619 break;
10620 }
10621 }
10622 }
10623
10624 // Combo right-click menu
10625 if(!clickedffc)
10626 {
10627 int warpindex = Map.warpindex(scr->data[c]);
10628 string txt_twarp_follow, txt_twarp_edit, txt_ffc_edit, txt_ffc_paste;
10629 bool show_ffcs = earliestfreeffc < MAXFFCS;
10630 bool dis_paste_ffc = Map.getCopyFFC() < 0;
10631 bool show_warps = warpindex > -1;
10632 bool show_warpback = Map.has_warpback();
10633 // FFC-specific options
10634 if(earliestfreeffc < MAXFFCS)
10635 {
10636 txt_ffc_edit = fmt::format("Edit New FFC {}",earliestfreeffc+1);
10637 if(Map.getCopyFFC()>-1)
10638 txt_ffc_paste = fmt::format("Paste FFC as FFC {}",earliestfreeffc+1);
10639 else
10640 txt_ffc_paste = "Paste FFC";
10641 }
10642
10643 if(warpindex > -1)
10644 {
10645 char letter = warpindex==4 ? 'R' : 'A'+warpindex;
10646 txt_twarp_follow = fmt::format("Follow Tile Warp {}",letter);
10647 txt_twarp_edit = fmt::format("Edit Tile Warp {}",letter);
10648 }
10649
10650 NewMenu draw_rc_menu
10651 {
10652 { "Select Combo", [&]()
10653 {
10654 Combo = draw_mapscr->data[c];
10655 if(AutoBrush)
10656 BrushWidth = BrushHeight = 1;
10657 }, nullopt, !draw_mapscr },
10658 { "Scroll to Combo", [&]()
10659 {
10660 First[current_combolist] = scrollto_cmb(draw_mapscr->data[c]);
10661 }, nullopt, !draw_mapscr },
10662 { "Edit Combo", [&]()
10663 {
10664 edit_combo(draw_mapscr->data[c],true,draw_mapscr->cset[c]);
10665 }, nullopt, !draw_mapscr },
10666 {},
10667 { "Replace All", [&](){replace(combo_pos);} },
10668 { "Draw Block", &draw_block_menu },
10669 { "Brush Settings ", &brush_menu },
10670 { "Set Fill Type ", &fill_menu },
10671 };
10672 if(show_warps || show_warpback)
10673 {
10674 draw_rc_menu.add_sep();
10675 if(show_warpback)
10676 draw_rc_menu.add({ "Warp Back", [&](){Map.warpback();} });
10677 if(show_warps)
10678 {
10679 draw_rc_menu.add({ txt_twarp_follow, [&](){follow_twarp(warpindex);} });
10680 draw_rc_menu.add({ txt_twarp_edit, [&](){edit_twarp(warpindex);} });
10681 }
10682 }
10683 if(show_ffcs)
10684 {
10685 draw_rc_menu.add_sep();
10686 draw_rc_menu.add({ txt_ffc_edit, [&]()
10687 {
10688 ffdata tempdat;
10689 // x, y are ints on ffdata (but ffc x, y are zfix), so *10000
10690 tempdat.x = ((int((x-startxint)/mapscreen_single_scale)&(~0x0007)) % 256) * 10000;
10691 tempdat.y = ((int((y-startyint)/mapscreen_single_scale)&(~0x0007)) % 176) * 10000;
10692 tempdat.data = Combo;
10693 tempdat.cset = CSet;
10694 call_ffc_dialog(earliestfreeffc, tempdat, active_visible_screen->scr, active_visible_screen->screen);
10695 } });
10696 draw_rc_menu.add({ txt_ffc_paste, [&]()
10697 {
10698 auto set_ffc_data = Map.getCopyFFCData();
10699 set_ffc_data.x = ((int((x-startxint)/mapscreen_single_scale)&(~0x0007)) % 256);
10700 set_ffc_data.y = ((int((y-startyint)/mapscreen_single_scale)&(~0x0007)) % 176);
10701 Map.DoSetFFCCommand(Map.getCurrMap(), active_visible_screen->screen, earliestfreeffc, set_ffc_data);
10702 }, nullopt, dis_paste_ffc });
10703 }
10704 draw_rc_menu.add_sep();
10705 draw_rc_menu.add({ "Screen", &rc_menu_screen });
10706 draw_rc_menu.pop(x,y);
10707 }
10708 }
10709 goto domouse_doneclick;
10710 }
10711
10712 //on the drawing mode button
10713 font = get_custom_font(CFONT_GUI);
10714 if(drawmode_btn.rect(x,y))
10715 {
10716 if(lclick)
10717 {
10718 if(do_text_button(drawmode_btn.x,drawmode_btn.y,drawmode_btn.w,drawmode_btn.h,dm_names[draw_mode]))
10719 onDrawingMode();
10720 }
10721 else if(rclick)
10722 drawing_mode_menu.pop(x,y);
10723 goto domouse_doneclick;
10724 }
10725 font=tfont;
10726
10727 //Squares
10728 //
10729 set_active_visible_screen(Map.CurrScr());
10730 {
10731 if(squarepanel_swap_btn.rect(x,y))
10732 {
10733 toggle_compact_sqr_mode();
10734 goto domouse_doneclick;
10735 }
10736 if(squarepanel_up_btn.rect(x,y))
10737 {
10738 cycle_compact_sqr(false);
10739 goto domouse_doneclick;
10740 }
10741 if(squarepanel_down_btn.rect(x,y))
10742 {
10743 cycle_compact_sqr(true);
10744 goto domouse_doneclick;
10745 }
10746
10747 bool do_dummyxy = false;
10748 bool dummymode = key[KEY_LSHIFT] || key[KEY_RSHIFT];
10749
10750 if(itemsqr_pos.rect(x,y))
10751 {
10752 if(dummymode) do_dummyxy = true;
10753 else
10754 {
10755 onItem();
10756
10757 if(!rclick && Map.CurrScr()->hasitem)
10758 doxypos(Map.CurrScr()->itemx,Map.CurrScr()->itemy,11,SNAP_HALF,SNAP_NONE);
10759 goto domouse_doneclick;
10760 }
10761 }
10762
10763 if(stairsqr_pos.rect(x,y))
10764 {
10765 if(dummymode) do_dummyxy = true;
10766 else
10767 {
10768 doxypos(Map.CurrScr()->stairx,Map.CurrScr()->stairy,14,SNAP_WHOLE);
10769 goto domouse_doneclick;
10770 }
10771 }
10772
10773 if(warparrival_pos.rect(x,y))
10774 {
10775 if(dummymode) do_dummyxy = true;
10776 else
10777 {
10778 if(get_qr(qr_NOARRIVALPOINT))
10779 {
10780 info_dsa("Arrival Square",
10781 "The arrival square cannot be used unless the QR 'Use Warp Return "
10782 "Points Only' under 'Quest->Options->Combos' is disabled."
10783 "\nGenerally, this square only exists for compatibility purposes, and is not used"
10784 " in creating new quests.",
10785 "dsa_warparrival");
10786 }
10787 else doxypos(Map.CurrScr()->warparrivalx,Map.CurrScr()->warparrivaly,10,SNAP_HALF,SNAP_NONE);
10788 goto domouse_doneclick;
10789 }
10790 }
10791
10792 if(flagsqr_pos.rect(x,y))
10793 {
10794 if(dummymode) do_dummyxy = true;
10795 else
10796 {
10797 onFlags();
10798 goto domouse_doneclick;
10799 }
10800 }
10801
10802 for(auto q = 0; q < 4; ++q)
10803 {
10804 if(warpret_pos[q].rect(x,y))
10805 {
10806 if(dummymode) do_dummyxy = true;
10807 else
10808 {
10809 doxypos(Map.CurrScr()->warpreturnx[q],Map.CurrScr()->warpreturny[q],9,SNAP_HALF,SNAP_NONE);
10810 goto domouse_doneclick;
10811 }
10812 }
10813 }
10814
10815 if(enemy_prev_pos.rect(x,y))
10816 {
10817 if(dummymode) do_dummyxy = true;
10818 else
10819 {
10820 onEnemies();
10821 goto domouse_doneclick;
10822 }
10823 }
10824
10825 if(do_dummyxy)
10826 {
10827 byte x = 0, y = 0;
10828 showxypos_dummy = true;
10829 doxypos(x,y,13,SNAP_HALF,SNAP_NONE);
10830 goto domouse_doneclick;
10831 }
10832 }
10833
10834 if(draw_mode==dm_alias)
10835 {
10836 for(int32_t j=0; j<num_combo_cols; ++j)
10837 {
10838 if(combolistscrollers[j].rectind(x,y)==0 && !mouse_down)
10839 {
10840 scrollup(j);
10841 goto domouse_doneclick;
10842 }
10843 else if(combolistscrollers[j].rectind(x,y)==1 && !mouse_down)
10844 {
10845 scrolldown(j);
10846 goto domouse_doneclick;
10847 }
10848 else if(comboaliaslist[j].rect(x,y))
10849 {
10850 select_comboa(j);
10851
10852 if(rclick && comboaliaslist[j].rect(gui_mouse_x(),gui_mouse_y()))
10853 popup_cpane_rc(x, y);
10854 goto domouse_doneclick;
10855 }
10856 }
10857 }
10858 else if(draw_mode==dm_cpool)
10859 {
10860 for(int32_t j=0; j<num_combo_cols; ++j)
10861 {
10862 if(combolistscrollers[j].rectind(x,y)==0 && !mouse_down)
10863 {
10864 scrollup(j);
10865 goto domouse_doneclick;
10866 }
10867 else if(combolistscrollers[j].rectind(x,y)==1 && !mouse_down)
10868 {
10869 scrolldown(j);
10870 goto domouse_doneclick;
10871 }
10872 else if(comboaliaslist[j].rect(x,y))
10873 {
10874 select_combop(j);
10875
10876 if(rclick && comboaliaslist[j].rect(gui_mouse_x(),gui_mouse_y()))
10877 popup_cpane_rc(x, y);
10878 goto domouse_doneclick;
10879 }
10880 }
10881 }
10882 else if (draw_mode == dm_auto)
10883 {
10884 for (int32_t j = 0; j < num_combo_cols; ++j)
10885 {
10886 if (combolistscrollers[j].rectind(x, y) == 0 && !mouse_down)
10887 {
10888 scrollup(j);
10889 goto domouse_doneclick;
10890 }
10891 else if (combolistscrollers[j].rectind(x, y) == 1 && !mouse_down)
10892 {
10893 scrolldown(j);
10894 goto domouse_doneclick;
10895 }
10896 else if (comboaliaslist[j].rect(x, y))
10897 {
10898 select_autocombo(j);
10899
10900 if(rclick && comboaliaslist[j].rect(gui_mouse_x(),gui_mouse_y()))
10901 popup_cpane_rc(x, y);
10902 goto domouse_doneclick;
10903 }
10904 }
10905 }
10906 else
10907 {
10908 for(int32_t j=0; j<num_combo_cols; ++j)
10909 {
10910 if(combolistscrollers[j].rectind(x,y)==0 && !mouse_down)
10911 {
10912 scrollup(j);
10913 goto domouse_doneclick;
10914 }
10915 else if(combolistscrollers[j].rectind(x,y)==1 && !mouse_down)
10916 {
10917 scrolldown(j);
10918 goto domouse_doneclick;
10919 }
10920 else if(combolist[j].rect(x,y))
10921 {
10922 select_combo(j);
10923
10924 if(rclick && combolist[j].rect(gui_mouse_x(),gui_mouse_y()))
10925 popup_cpane_rc(x, y);
10926 goto domouse_doneclick;
10927 }
10928 }
10929 }
10930
10931 //on the favorites list
10932 if(favorites_list.rect(x,y))
10933 {
10934 if(lclick)
10935 {
10936 int32_t f=favorites_list.rectind(x,y);
10937 int32_t row=f/favorites_list.w;
10938 int32_t col=f%favorites_list.w;
10939 f = (row*FAVORITECOMBO_PER_ROW)+col;
10940 int32_t fp = f + FAVORITECOMBO_PER_PAGE * FavoriteComboPage;
10941
10942 bool dmcond = favorite_combos[fp] < 0;
10943 if((key[KEY_LSHIFT] || key[KEY_RSHIFT] || dmcond) && !(CHECK_CTRL_CMD))
10944 {
10945 int32_t tempcb=ComboBrush;
10946 ComboBrush=0;
10947
10948 while(gui_mouse_b())
10949 {
10950 x=gui_mouse_x();
10951 y=gui_mouse_y();
10952
10953 switch(draw_mode)
10954 {
10955 case dm_alias:
10956 if (favorite_combos[fp] != combo_apos || favorite_combo_modes[fp] != dm_alias)
10957 {
10958 favorite_combo_modes[fp] = dm_alias;
10959 favorite_combos[fp] = combo_apos;
10960 saved = false;
10961 }
10962 break;
10963 case dm_cpool:
10964 if (favorite_combos[fp] != combo_pool_pos || favorite_combo_modes[fp] != dm_cpool)
10965 {
10966 favorite_combo_modes[fp] = dm_cpool;
10967 favorite_combos[fp] = combo_pool_pos;
10968 saved = false;
10969 }
10970 break;
10971 case dm_auto:
10972 if (favorite_combos[fp] != combo_auto_pos || favorite_combo_modes[fp] != dm_auto)
10973 {
10974 favorite_combo_modes[fp] = dm_auto;
10975 favorite_combos[fp] = combo_auto_pos;
10976 saved = false;
10977 }
10978 break;
10979 default:
10980 if (favorite_combos[fp] != Combo || favorite_combo_modes[fp] != dm_normal)
10981 {
10982 if (BrushWidth > 1 || BrushHeight > 1)
10983 {
10984 add_favorite_combo_block(f, Combo, key[KEY_LSHIFT] || key[KEY_RSHIFT]);
10985 break;
10986 }
10987 favorite_combo_modes[fp] = dm_normal;
10988 favorite_combos[fp] = Combo;
10989 saved = false;
10990 }
10991 }
10992
10993 custom_vsync();
10994 refresh(rALL | rFAVORITES);
10995 }
10996
10997 ComboBrush=tempcb;
10998 }
10999 else if(CHECK_CTRL_CMD)
11000 {
11001 int32_t tempcb=ComboBrush;
11002 ComboBrush=0;
11003
11004 while(gui_mouse_b())
11005 {
11006 x=gui_mouse_x();
11007 y=gui_mouse_y();
11008
11009 if(favorite_combos[fp]!=-1)
11010 {
11011 favorite_combo_modes[fp] = dm_normal;
11012 favorite_combos[fp]=-1;
11013 saved=false;
11014 }
11015
11016 custom_vsync();
11017 refresh(rALL | rFAVORITES);
11018 }
11019
11020 ComboBrush=tempcb;
11021 }
11022 else if(key[KEY_ALT] || key[KEY_ALTGR])
11023 {
11024 if(select_favorite())
11025 {
11026 switch(favorite_combo_modes[fp])
11027 {
11028 case dm_alias:
11029 combo_alistpos[current_comboalist]=scrollto_alias(combo_apos);
11030 break;
11031 case dm_cpool:
11032 combo_pool_listpos[current_cpoollist] = scrollto_cpool(combo_pool_pos);
11033 break;
11034 case dm_auto:
11035 combo_auto_listpos[current_cautolist] = scrollto_cauto(combo_auto_pos);
11036 break;
11037 default:
11038 First[current_combolist]=scrollto_cmb(Combo);
11039 }
11040 }
11041 }
11042 else
11043 {
11044 select_favorite();
11045 }
11046 }
11047 else if(rclick)
11048 {
11049 bool valid=select_favorite();
11050
11051 if(valid)
11052 {
11053 int f = favorites_list.rectind(x,y);
11054 int row = f/favorites_list.w;
11055 int col = f%favorites_list.w;
11056 f = (row*FAVORITECOMBO_PER_ROW) + col + (FAVORITECOMBO_PER_PAGE * FavoriteComboPage);
11057 popup_favorites_rc(f, x, y);
11058 }
11059 }
11060 goto domouse_doneclick;
11061 }
11062
11063 //on the commands buttons
11064 int32_t cmd = commands_list.rectind(x,y);
11065 if(cmd > -1)
11066 {
11067 uint hkey = favorite_commands[cmd];
11068 bool shift=(key[KEY_LSHIFT] || key[KEY_RSHIFT]);
11069 bool ctrl=(CHECK_CTRL_CMD);
11070 bool alt=(key[KEY_ALT] || key[KEY_ALTGR]);
11071 bool dis = disabled_hotkey(hkey);
11072 auto& btn = commands_list.subsquare(cmd);
11073 if(!dis||rclick||shift||ctrl||alt)
11074 {
11075 FONT *tfont=font;
11076 font=get_custom_font(CFONT_FAVCMD);
11077 if(do_layer_button_reset(btn.x,btn.y,btn.w,btn.h,
11078 get_hotkey_name(hkey),
11079 selected_hotkey(hkey)?D_SELECTED:0,
11080 true))
11081 {
11082 font=tfont;
11083 if(alt)
11084 {
11085 show_hotkey_info(hkey);
11086 }
11087 else if(ctrl)
11088 {
11089 write_fav_command(cmd,0);
11090 }
11091 else if(rclick || shift || hkey==ZQKEY_NULL_KEY)
11092 {
11093 if(auto newkey = select_fav_command())
11094 write_fav_command(cmd,*newkey);
11095 }
11096 else
11097 {
11098 run_hotkey(hkey);
11099 }
11100 }
11101
11102 font=tfont;
11103 }
11104 goto domouse_doneclick;
11105 }
11106 }
11107
11108 domouse_doneclick:
11109 mouse_down |= mb&3;
11110
11111 if(mouse_z!=0)
11112 {
11113 int32_t z=0;
11114
11115 for(int32_t j=0; j<num_combo_cols; ++j)
11116 {
11117 z=abs(mouse_z);
11118
11119 if(key[KEY_ALT]||key[KEY_ALTGR])
11120 {
11121 z*=combolist[j].h;
11122 }
11123
11124
11125 if(draw_mode == dm_alias)
11126 {
11127 if(comboaliaslist[j].rect(x,y))
11128 {
11129 if(mouse_z<0) //scroll down
11130 {
11131 combo_alistpos[current_comboalist] = zc_min(MAXCOMBOALIASES - comboaliaslist[j].w*comboaliaslist[j].h,
11132 combo_alistpos[current_comboalist]+comboaliaslist[j].w*z);
11133 }
11134 else //scroll up
11135 {
11136 if(combo_alistpos[current_comboalist]>0)
11137 {
11138 combo_alistpos[current_comboalist]-=zc_min(combo_alistpos[current_comboalist],comboaliaslist[j].w*z);
11139 }
11140 }
11141 goto domouse_donez;
11142 }
11143 }
11144 else if(draw_mode == dm_cpool)
11145 {
11146 if(comboaliaslist[j].rect(x,y))
11147 {
11148 if(mouse_z<0) //scroll down
11149 {
11150 combo_pool_listpos[current_cpoollist] = zc_min(MAXCOMBOPOOLS - comboaliaslist[j].w*comboaliaslist[j].h,
11151 combo_pool_listpos[current_cpoollist]+comboaliaslist[j].w*z);
11152 }
11153 else //scroll up
11154 {
11155 if(combo_pool_listpos[current_cpoollist]>0)
11156 {
11157 combo_pool_listpos[current_cpoollist]-=zc_min(combo_pool_listpos[current_cpoollist],comboaliaslist[j].w*z);
11158 }
11159 }
11160 goto domouse_donez;
11161 }
11162 }
11163 else if (draw_mode == dm_auto)
11164 {
11165 if (comboaliaslist[j].rect(x, y))
11166 {
11167 if (mouse_z < 0) //scroll down
11168 {
11169 combo_auto_listpos[current_cautolist] = zc_min(MAXAUTOCOMBOS - comboaliaslist[j].w * comboaliaslist[j].h,
11170 combo_auto_listpos[current_cautolist] + comboaliaslist[j].w * z);
11171 }
11172 else //scroll up
11173 {
11174 if (combo_auto_listpos[current_cautolist] > 0)
11175 {
11176 combo_auto_listpos[current_cautolist] -= zc_min(combo_auto_listpos[current_cautolist], comboaliaslist[j].w * z);
11177 }
11178 }
11179 goto domouse_donez;
11180 }
11181 }
11182 else
11183 {
11184 if(combolist[j].rect(x,y))
11185 {
11186 if(mouse_z<0) //scroll down
11187 {
11188 First[current_combolist] = zc_min(MAXCOMBOS-combolist[j].w*combolist[j].h,
11189 First[current_combolist] + combolist[j].w*z);
11190 }
11191 else //scroll up
11192 {
11193 if(First[current_combolist]>0)
11194 {
11195 First[current_combolist]-=zc_min(First[current_combolist],combolist[j].w*z);
11196 }
11197 }
11198 goto domouse_donez;
11199 }
11200 }
11201 }
11202
11203 z=abs(mouse_z);
11204
11205 if(real_mini.rect(x,y))
11206 {
11207 for(int32_t i=0; i<z; ++i)
11208 {
11209 if(mouse_z>0) onIncMap();
11210 else onDecMap();
11211 }
11212 goto domouse_donez;
11213 }
11214
11215 if(is_compact && compact_square_panels
11216 && squares_panel.rect(x,y))
11217 {
11218 cycle_compact_sqr(mouse_z < 0);
11219 goto domouse_donez;
11220 }
11221 domouse_donez:
11222 position_mouse_z(0);
11223 }
11224 font = tfont;
11225 active_visible_screen = nullptr;
11226 }
11227
11228 int32_t d_viewpal_proc(int32_t msg, DIALOG *d, int32_t c)
11229 {
11230 int32_t ret = d_bitmap_proc(msg, d, c);
11231 char* buf = (char*)d->dp2; //buffer to store the color code in
11232 DIALOG* d2 = (DIALOG*)d->dp3; //DIALOG* to update the text proc
11233 if(!buf)
11234 return ret;
11235 switch(msg)
11236 {
11237 case MSG_IDLE:
11238 case MSG_GOTMOUSE:
11239 case MSG_LOSTMOUSE:
11240 break;
11241 default:
11242 return ret;
11243 }
11244 char t[16];
11245 memcpy(t, buf, 16);
11246 int32_t x = gui_mouse_x() - d->x;
11247 int32_t y = gui_mouse_y() - d->y;
11248 if(msg != MSG_LOSTMOUSE && isinRect(x, y, 0, 0, d->w-1, d->h-1))
11249 {
11250 float palscale = 1.5;
11251 for(int32_t i = 0; i<256; ++i)
11252 if(isinRect(x,y,(int32_t)(((i&31)<<3)*palscale),(int32_t)(((i&0xE0)>>2)*palscale), (int32_t)((((i&31)<<3)+7)*palscale),(int32_t)((((i&0xE0)>>2)+7)*palscale)))
11253 {
11254 sprintf(buf, "0x%02X (%03d) ", i, i); //Extra spaces to increase drawn width, so it draws the blank area
11255 break;
11256 }
11257 }
11258 else memset(buf, ' ', 15);
11259 if(strcmp(buf, t) && d2 && d2->proc == jwin_text_proc && d2->dp == d->dp2)
11260 object_message(d2, MSG_DRAW, 0);
11261 return ret;
11262 }
11263
11264 static DIALOG showpal_dlg[] =
11265 {
11266 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
11267 { jwin_win_proc, 24, 68, 272, 119, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "View Palette", NULL, NULL },
11268 { jwin_frame_proc, 30, 76+16, 260, 68, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
11269 { d_viewpal_proc, 32, 76+18, 256, 64, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
11270 { jwin_text_proc, 32+8,76+18+66, 20, 8, vc(11), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
11271 { jwin_button_proc, 130, 144+18, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
11272 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
11273 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
11274 };
11275
11276 int32_t onShowPal()
11277 {
11278 float palscale = 1.5;
11279
11280 BITMAP *palbmp = create_bitmap_ex(8,(int32_t)(256*palscale),(int32_t)(64*palscale));
11281
11282 if(!palbmp)
11283 return D_O_K;
11284 clear_to_color(palbmp,jwin_pal[jcBOX]); //If not cleared, random static appears between swatches! -E
11285 showpal_dlg[0].dp2=get_zc_font(font_lfont);
11286
11287 for(int32_t i=0; i<256; i++)
11288 rectfill(palbmp,(int32_t)(((i&31)<<3)*palscale),(int32_t)(((i&0xE0)>>2)*palscale), (int32_t)((((i&31)<<3)+7)*palscale),(int32_t)((((i&0xE0)>>2)+7)*palscale),i);
11289 showpal_dlg[2].dp=(void *)palbmp;
11290 char buf[16] = {0};
11291 showpal_dlg[2].dp2=(void *)buf;
11292 showpal_dlg[2].dp3=(void *)&(showpal_dlg[3]);
11293 showpal_dlg[3].dp=(void *)buf;
11294 showpal_dlg[3].dp2=(void *)get_zc_font(font_deffont);
11295
11296 large_dialog(showpal_dlg);
11297 do_zqdialog(showpal_dlg,2);
11298 destroy_bitmap(palbmp);
11299 return D_O_K;
11300 }
11301
11302 static DIALOG csetfix_dlg[] =
11303 {
11304 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
11305 { jwin_win_proc, 72, 80, 176+1, 96+1, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "CSet Fix", NULL, NULL },
11306 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
11307 { jwin_radio_proc, 104+22, 108, 80+1, 8+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "Full Screen", NULL, NULL },
11308 { jwin_radio_proc, 104+22, 118+2, 80+1, 8+1, vc(14), vc(1), 0, D_SELECTED, 0, 0, (void *) "Dungeon Floor", NULL, NULL },
11309 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
11310 { jwin_check_proc, 104+22, 128+4, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, (void *) "All Layers", NULL, NULL },
11311 { jwin_button_proc, 90, 152, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
11312 { jwin_button_proc, 170, 152, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
11313 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
11314 };
11315
11316 int32_t onCSetFix()
11317 {
11318 restore_mouse();
11319 csetfix_dlg[0].dp2=get_zc_font(font_lfont);
11320 int32_t s=2,x2=14,y2=9;
11321
11322 large_dialog(csetfix_dlg);
11323
11324 if(do_zqdialog(csetfix_dlg,-1)==6)
11325 {
11326 if(csetfix_dlg[2].flags&D_SELECTED)
11327 {
11328 s=0;
11329 x2=16;
11330 y2=11;
11331 }
11332
11333 if(csetfix_dlg[5].flags&D_SELECTED)
11334 {
11335 /*
11336 int32_t drawmap, drawscr;
11337 if (CurrentLayer==0)
11338 {
11339 drawmap=Map.getCurrMap();
11340 drawscr=Map.getCurrScr();
11341 }
11342 else
11343 {
11344 drawmap=Map.CurrScr()->layermap[CurrentLayer-1]-1;
11345 drawscr=Map.CurrScr()->layerscreen[CurrentLayer-1];
11346 }
11347 mapscr* draw_mapscr = Map.AbsoluteScr(drawmap, drawscr);
11348 if(!draw_mapscr) return;
11349 saved=false;
11350 Map.Ugo();
11351
11352 if(!(draw_mapscr->valid&mVALID))
11353 {
11354 Map.CurrScr()->valid|=mVALID;
11355 draw_mapscr->valid|=mVALID;
11356 Map.setcolor(Color);
11357 }
11358 for(int32_t i=0; i<176; i++)
11359 {
11360 draw_mapscr->data[i]=Combo;
11361 draw_mapscr->cset[i]=CSet;
11362 }
11363 refresh(rMAP+rSCRMAP);
11364 */
11365 }
11366
11367 Map.StartListCommand();
11368 for(int32_t y=s; y<y2; y++)
11369 {
11370 for(int32_t x=s; x<x2; x++)
11371 {
11372 Map.DoSetComboCommand(Map.getCurrMap(), Map.getCurrScr(), (y<<4)+x, -1, CSet);
11373 }
11374 }
11375 Map.FinishListCommand();
11376
11377 refresh(rMAP);
11378 saved = false;
11379 }
11380
11381 return D_O_K;
11382 }
11383 static bool doAllSolidWater()
11384 {
11385 for(int32_t i=0; i < MAXCOMBOS; ++i)
11386 {
11387 if(combo_class_buf[combobuf[i].type].water!=0)
11388 {
11389 combobuf[i].walk |= 0x0F; //Solid
11390 }
11391 }
11392 return true;
11393 }
11394 static bool doNoSolidWater()
11395 {
11396 for(int32_t i=0; i < MAXCOMBOS; ++i)
11397 {
11398 if(combo_class_buf[combobuf[i].type].water!=0)
11399 {
11400 combobuf[i].walk &= ~0x0F; //Non-solid
11401 }
11402 }
11403 return true;
11404 }
11405 int32_t onWaterSolidity()
11406 {
11407 AlertFuncDialog("Water Conversion",
11408 "Forcibly set the solidity of all 'Liquid' combos in the quest?",
11409 ""
11410 ).add_buttons(2,
11411 { "Solid", "Non-Solid", "Cancel" },
11412 { doAllSolidWater, doNoSolidWater, nullptr }
11413 ).show();
11414 return D_O_K;
11415 }
11416
11417 static bool doAllEffectSquare()
11418 {
11419 for(int32_t i=0; i < MAXCOMBOS; ++i)
11420 {
11421 combobuf[i].walk |= 0xF0; //Effect
11422 }
11423 return true;
11424 }
11425 static bool doBlankEffectSquare()
11426 {
11427 for(int32_t i=0; i < MAXCOMBOS; ++i)
11428 {
11429 if(combobuf[i].is_blank(true))
11430 {
11431 combobuf[i].walk |= 0xF0; //Effect
11432 }
11433 }
11434 return true;
11435 }
11436
11437 int32_t onEffectFix()
11438 {
11439 AlertFuncDialog("Effect Square Conversion",
11440 "Forcibly fill the green effect square of all combos in the quest?",
11441 ""
11442 ).add_buttons(2,
11443 { "All", "Blank Only", "Cancel" },
11444 { doAllEffectSquare, doBlankEffectSquare, nullptr }
11445 ).show();
11446 return D_O_K;
11447 }
11448
11449 static bool clear_green_arrival_squares()
11450 {
11451 for(mapscr& scr : TheMaps)
11452 {
11453 if(!scr.valid) continue;
11454 scr.warparrivalx = 0;
11455 scr.warparrivaly = 0;
11456 }
11457 set_qr(qr_NOARRIVALPOINT, true);
11458 return true;
11459 }
11460
11461 static bool replace_green_arrival_squares()
11462 {
11463 // Check for conflicts first
11464 bool has_conflicts = false;
11465
11466 for(mapscr& scr : TheMaps)
11467 {
11468 if(!scr.valid) continue;
11469 if(!(scr.warparrivalx || scr.warparrivaly)) continue;
11470 if(scr.warpreturnx[0] || scr.warpreturny[0])
11471 {
11472 has_conflicts = true;
11473 break;
11474 }
11475 }
11476
11477 enum
11478 {
11479 NOT_ASKED = -1,
11480 MODE_FORCE, MODE_IGNORE, MODE_FIND_IGNORE, MODE_FIND_FORCE, MODE_CANCEL
11481 };
11482 int mode = NOT_ASKED;
11483
11484 if(has_conflicts)
11485 {
11486 AlertFuncDialog("Handle Conflicts",
11487 "Warp Square A is not available for all screens that have arrival squares."
11488 " How should this be handled? (See '?' for more info)",
11489 "Overwrite A: Replace the existing warp return square A with the position of the green arrival square"
11490 "\nIgnore: Do nothing if warp return square A exists"
11491 "\nFind Space or Ignore: Choose another, unused, square to set to the position of the green arrival square."
11492 " If none are unused, 'Ignore' instead."
11493 "\nFind Space or Overwrite: Choose another, unused square to set to the position of the green arrival square."
11494 " If none are unused, 'Overwrite A' instead."
11495 "\nCancel: Don't do anything"
11496 ).add_buttons(1,
11497 { "Overwrite A", "Ignore", "Find Space or Ignore", "Find Space or Overwrite A", "Cancel" },
11498 mode
11499 ).show();
11500 if(mode == NOT_ASKED || mode == MODE_CANCEL)
11501 return false;
11502 }
11503 for(mapscr& scr : TheMaps)
11504 {
11505 if(!scr.valid) continue;
11506 if(!(scr.warparrivalx || scr.warparrivaly)) continue;
11507 int indx = 0;
11508 if(scr.warpreturnx[0] || scr.warpreturny[0])
11509 {
11510 if(mode == MODE_IGNORE) continue; // Warp A not free, so ignore
11511 if(mode != MODE_FORCE)
11512 {
11513 for(int q = 1; q < 4; ++q)
11514 {
11515 if(scr.warpreturnx[q] || scr.warpreturny[q])
11516 continue;
11517 indx = q; // Use this warp, since it's free
11518 break;
11519 }
11520 if(indx == 0 && mode == MODE_FIND_IGNORE)
11521 continue; // Nothing free, so ignore
11522 }
11523 }
11524 scr.warpreturnx[indx] = scr.warparrivalx;
11525 scr.warpreturny[indx] = scr.warparrivaly;
11526 scr.warparrivalx = 0;
11527 scr.warparrivaly = 0;
11528 }
11529 set_qr(qr_NOARRIVALPOINT, true);
11530 return true;
11531 }
11532
11533 int32_t onRemoveOldArrivalSquare()
11534 {
11535 AlertFuncDialog("Arrival Square Removal",
11536 "Clear the old green 'Arrival' squares for the whole quest?"
11537 "\n(There will be no further confirmation, and this operation cannot be undone)",
11538 ""
11539 ).add_buttons(2,
11540 { "Replace With Blue Return Square", "Clear Completely", "Cancel" },
11541 { replace_green_arrival_squares, clear_green_arrival_squares, nullptr }
11542 ).show();
11543 return D_O_K;
11544 }
11545
11546 byte* getPalPointer(int32_t pal, int32_t cset)
11547 {
11548 if (pal < 0) return colordata + CSET(cset)*3;
11549 byte* ret = colordata + CSET(pal*pdLEVEL+poLEVEL)*3;
11550 switch(cset)
11551 {
11552 case 2: case 3: case 4:
11553 return ret + CSET(cset-2)*3;
11554 case 9:
11555 return ret + CSET(3)*3;
11556 case 1:
11557 return ret + CSET(13)*3;
11558 case 5:
11559 return ret + CSET(14)*3;
11560 case 7:
11561 return ret + CSET(15)*3;
11562 case 8:
11563 return ret + CSET(16)*3;
11564 }
11565 return NULL;
11566 }
11567
11568 void copyCSet(int32_t destpal, int32_t destcset, int32_t srcpal, int32_t srccset)
11569 {
11570 byte* dest = getPalPointer(destpal, destcset);
11571 byte* src = getPalPointer(srcpal, srccset);
11572 if (dest && src)
11573 {
11574 memcpy(dest, src, 16*3);
11575 }
11576 }
11577
11578 void setColorPalette(int32_t flags, int32_t lowpal, int32_t highpal)
11579 {
11580 for (auto q = lowpal; q <= highpal; ++q)
11581 {
11582 for (auto c = 0; c < 12; ++c)
11583 {
11584 if (!(flags&(1<<c))) continue;
11585 copyCSet(q, c, -1, c);
11586 }
11587 }
11588 }
11589
11590 void setPitDamage(int32_t flags, int32_t lowcombo, int32_t highcombo, int32_t damage)
11591 {
11592 for(int32_t i=lowcombo; i < highcombo; ++i)
11593 {
11594 if((combobuf[i].type == cPITFALL && (flags & (1<<0)))
11595 || (combobuf[i].type == cWATER && !(combobuf[i].usrflags & (1<<0)) && (flags & (1<<1)))
11596 || (combobuf[i].type == cWATER && (combobuf[i].usrflags & (1<<0)) && (flags & (1<<2))))
11597 {
11598 if ((combobuf[i].type != cPITFALL || (flags & (1<<9)) || !(combobuf[i].usrflags & (1<<0)))
11599 && ((flags & (1<<8)) || combobuf[i].attributes[0] == 0))
11600 combobuf[i].attributes[0] = damage*10000;
11601 }
11602 }
11603 }
11604
11605 static DIALOG template_dlg[] =
11606 {
11607 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
11608 { jwin_win_proc, 72, 80, 176+1, 116+1, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "NES Dungeon Template", NULL, NULL },
11609 { d_comboframe_proc, 178, 122+3, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
11610 { d_combo_proc, 180, 124+3, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
11611 // { d_bitmap_proc, 180, 104, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
11612 { jwin_radio_proc, 104+33, 128+3, 64+1, 8+1, vc(14), vc(1), 0, D_SELECTED, 0, 0, (void *) "Floor:", NULL, NULL },
11613 { jwin_radio_proc, 104+33, 148+3, 64+1, 8+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "No Floor", NULL, NULL },
11614 { jwin_button_proc, 90, 172, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
11615 { jwin_button_proc, 170, 172, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
11616 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
11617 { jwin_text_proc, 104, 102, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "This copies the contents of", NULL, NULL },
11618 { jwin_text_proc, 104, 112, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "screen 83 of the current map.", NULL, NULL },
11619 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
11620 };
11621
11622 int32_t onTemplate()
11623 {
11624 static bool donethis=false;
11625
11626 if(!donethis||!(key[KEY_LSHIFT]||key[KEY_RSHIFT]))
11627 {
11628 template_dlg[2].d1=Combo;
11629 template_dlg[2].fg=CSet;
11630 donethis=true;
11631 }
11632
11633 restore_mouse();
11634
11635 if(Map.getCurrScr()==TEMPLATE)
11636 return D_O_K;
11637
11638 // BITMAP *floor_bmp = create_bitmap_ex(8,16,16);
11639 // if(!floor_bmp) return D_O_K;
11640 template_dlg[0].dp2=get_zc_font(font_lfont);
11641 // put_combo(floor_bmp,0,0,Combo,CSet,0,0);
11642 // template_dlg[2].dp=floor_bmp;
11643
11644 large_dialog(template_dlg);
11645
11646 if(do_zqdialog(template_dlg,-1)==5)
11647 {
11648 saved=false;
11649 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
11650 Map.DoTemplateCommand((template_dlg[3].flags==D_SELECTED) ? template_dlg[2].d1 : -1, template_dlg[2].fg, screen);
11651 refresh(rMAP+rSCRMAP);
11652 }
11653
11654 // destroy_bitmap(floor_bmp);
11655 return D_O_K;
11656 }
11657
11658 int32_t d_sel_scombo_proc(int32_t msg, DIALOG *d, int32_t c)
11659 {
11660 //these are here to bypass compiler warnings about unused arguments
11661 c=c;
11662
11663 switch(msg)
11664 {
11665 case MSG_CLICK:
11666 while(gui_mouse_b())
11667 {
11668 int32_t x = zc_min(zc_max(gui_mouse_x() - d->x,0)>>4, 15);
11669 int32_t y = zc_min(zc_max(gui_mouse_y() - d->y,0)&0xF0, 160);
11670
11671 if(x+y != d->d1)
11672 {
11673 d->d1 = x+y;
11674 custom_vsync();
11675 d_sel_scombo_proc(MSG_DRAW,d,0);
11676 }
11677 }
11678
11679 break;
11680
11681 case MSG_DRAW:
11682 {
11683 blit((BITMAP*)(d->dp),screen,0,0,d->x,d->y,d->w,d->h);
11684 int32_t x = d->x + (((d->d1)&15)<<4);
11685 int32_t y = d->y + ((d->d1)&0xF0);
11686 rect(screen,x,y,x+15,y+15,vc(15));
11687 }
11688 break;
11689 }
11690
11691 return D_O_K;
11692 }
11693
11694 static DIALOG cflag_dlg[] =
11695 {
11696 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
11697 12 { jwin_win_proc, 60-12, 40, 200+24, 148, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
11698 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
11699 12 { jwin_abclist_proc, 72-12-4, 60+4, 176+24+8, 92+3, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, D_EXIT, 0, 0, NULL, NULL, NULL },
11700 12 { jwin_button_proc, 70, 163, 51, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
11701 12 { jwin_button_proc, 190, 163, 51, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
11702 12 { jwin_button_proc, 130, 163, 51, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Help", NULL, NULL },
11703 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
11704 };
11705
11706
11707 void questrev_help()
11708 {
11709 jwin_alert("Help","The revision number of your quest.",NULL,NULL,"O&K",NULL,'k',16,get_zc_font(font_lfont));
11710 }
11711
11712 void questminrev_help()
11713 {
11714 jwin_alert("Help","If a player's saved game was from a revision less than the minimum", "revision, they have to restart from the beginning.", "This is useful if you make major changes to your quest.","O&K",NULL,'k',16,get_zc_font(font_lfont));
11715 }
11716
11717 int32_t select_cflag(const char *prompt,int32_t flag)
11718 {
11719 cflag_dlg[0].dp=(void *)prompt;
11720 cflag_dlg[0].dp2=get_zc_font(font_lfont);
11721 GUI::ListData ld = GUI::ZCListData::mapflag(numericalFlags, true);
11722 ListData select_cflag_list = ld.getJWin(&font);
11723 auto index = ld.findIndex(flag);
11724 cflag_dlg[2].d1=index.value_or(0);
11725 cflag_dlg[2].dp=(void *) &select_cflag_list;
11726
11727 large_dialog(cflag_dlg);
11728
11729 int32_t ret;
11730
11731 do
11732 {
11733 ret=do_zqdialog(cflag_dlg,2);
11734
11735 if(ret==5)
11736 {
11737 cflag_help(ld.getValue(cflag_dlg[2].d1));
11738 }
11739 }
11740 while(ret==5);
11741
11742 if(ret==0||ret==4)
11743 {
11744 position_mouse_z(0);
11745 return -1;
11746 }
11747
11748 return ld.getValue(cflag_dlg[2].d1);
11749 }
11750
11751 int32_t select_flag(int32_t &f)
11752 {
11753 int32_t ret=select_cflag("Flag Type",f);
11754
11755 if(ret>=0)
11756 {
11757 f=ret;
11758 return true;
11759 }
11760
11761 return false;
11762 }
11763
11764 int32_t d_scombo_proc(int32_t msg,DIALOG *d,int32_t c)
11765 {
11766 //these are here to bypass compiler warnings about unused arguments
11767 c=c;
11768
11769 switch(msg)
11770 {
11771 case MSG_CLICK:
11772 {
11773 int32_t c2=d->d1;
11774 int32_t cs=d->fg;
11775 int32_t f=d->d2;
11776
11777 if(d->bg==1 || (CHECK_CTRL_CMD))
11778 {
11779 while(gui_mouse_b())
11780 {
11781 /* do nothing */
11782 rest(1);
11783 }
11784
11785 if(select_flag(f))
11786 {
11787 d->d2=f;
11788
11789 }
11790 }
11791 else if(key[KEY_LSHIFT])
11792 {
11793 if(gui_mouse_b()&1)
11794 {
11795 d->d1++;
11796
11797 if(d->d1>=MAXCOMBOS) d->d1=0;
11798 }
11799 else if(gui_mouse_b()&2)
11800 {
11801 d->d1--;
11802
11803 if(d->d1<0) d->d1=MAXCOMBOS-1;
11804 }
11805 }
11806 else if(key[KEY_RSHIFT])
11807 {
11808 if(gui_mouse_b()&1)
11809 {
11810 d->fg++;
11811
11812 if(d->fg>11) d->fg=0;
11813 }
11814 else if(gui_mouse_b()&2)
11815 {
11816 d->fg--;
11817
11818 if(d->fg<0) d->fg=11;
11819 }
11820 }
11821 else if(key[KEY_ALT])
11822 {
11823 if(gui_mouse_b()&1)
11824 {
11825 d->d1 = Combo;
11826 d->fg = CSet;
11827 }
11828 }
11829 else
11830 {
11831 if(select_combo_2(c2, cs))
11832 {
11833 d->d1=c2;
11834 d->fg=cs;
11835 }
11836 }
11837
11838 return D_REDRAW;
11839 }
11840 break;
11841
11842 case MSG_DRAW:
11843 d->w = 32;
11844 d->h = 32;
11845
11846 BITMAP *buf = create_bitmap_ex(8,16,16);
11847 BITMAP *bigbmp = create_bitmap_ex(8,d->w,d->h);
11848
11849 if(buf && bigbmp)
11850 {
11851 clear_bitmap(buf);
11852
11853 if(d->bg) //flags only
11854 {
11855 put_flag(buf,0,0,d->d2);
11856 }
11857 else if(d->d1)
11858 {
11859 putcombo(buf,0,0,d->d1,d->fg);
11860
11861 if(Flags&cFLAGS)
11862 put_flags(buf,0,0,d->d1,d->fg,cFLAGS,d->d2);
11863 }
11864
11865 stretch_blit(buf, bigbmp, 0,0, 16, 16, 0, 0, d->w, d->h);
11866 destroy_bitmap(buf);
11867 blit(bigbmp,screen,0,0,d->x-1,d->y-1,d->w,d->h);
11868 destroy_bitmap(bigbmp);
11869 }
11870
11871
11872 /*BITMAP *buf = create_bitmap_ex(8,16,16);
11873 if(buf)
11874 {
11875 clear_bitmap(buf);
11876 if(d->d1)
11877 putcombo(buf,0,0,d->d1,d->fg);
11878
11879 blit(buf,screen,0,0,d->x,d->y,d->w,d->h);
11880 destroy_bitmap(buf);
11881 }*/
11882 break;
11883 }
11884
11885 return D_O_K;
11886 }
11887
11888 /*int32_t d_scombo2_proc(int32_t msg, DIALOG *d, int32_t c)
11889 {
11890 //these are here to bypass compiler warnings about unused arguments
11891 c=c;
11892
11893 switch(msg)
11894 {
11895 case MSG_CLICK:
11896 if (CHECK_CTRL_CMD)
11897 {
11898 select_scombo(d->d1);
11899 }
11900 else
11901 {
11902 select_scombo(d->d1);
11903 }
11904 d_scombo_proc(MSG_DRAW,d,0);
11905 break;
11906
11907
11908 case MSG_DRAW:
11909 BITMAP *buf = create_bitmap_ex(8,16,16);
11910 if(buf)
11911 {
11912 clear_bitmap(buf);
11913 Map.draw_secret2(buf,d->d1);
11914 blit(buf,screen,0,0,d->x,d->y,16,16);
11915 destroy_bitmap(buf);
11916 }
11917 break;
11918 }
11919
11920 return D_O_K;
11921 }*/
11922
11923 int32_t onSecretF();
11924
11925 static int32_t secret_burn_list[] =
11926 {
11927 // dialog control number
11928 4, 5, 6, 7, 48, 49, 50, 51, 92, 93, 94, 95, -1
11929 };
11930
11931 static int32_t secret_arrow_list[] =
11932 {
11933 // dialog control number
11934 8, 9, 10, 52, 53, 54, 96, 97, 98, -1
11935 };
11936
11937 static int32_t secret_bomb_list[] =
11938 {
11939 // dialog control number
11940 11, 12, 55, 56, 99, 100, -1
11941 };
11942
11943 static int32_t secret_boomerang_list[] =
11944 {
11945 // dialog control number
11946 13, 14, 15, 57, 58, 59, 101, 102, 103, -1
11947 };
11948
11949 static int32_t secret_magic_list[] =
11950 {
11951 // dialog control number
11952 16, 17, 60, 61, 104, 105, -1
11953 };
11954
11955 static int32_t secret_sword_list[] =
11956 {
11957 // dialog control number
11958 18, 19, 20, 21, 22, 23, 24, 25, 62, 63, 64, 65, 66, 67, 68, 69, 106, 107, 108, 109, 110, 111, 112, 113, -1
11959 };
11960
11961 static int32_t secret_misc_list[] =
11962 {
11963 // dialog control number
11964 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, -1
11965 };
11966
11967 static TABPANEL secret_tabs[] =
11968 {
11969 // (text)
11970 { (char *)"Burn", D_SELECTED, secret_burn_list, 0, NULL },
11971 { (char *)"Arrow", 0, secret_arrow_list, 0, NULL },
11972 { (char *)"Bomb", 0, secret_bomb_list, 0, NULL },
11973 { (char *)"Boomerang", 0, secret_boomerang_list, 0, NULL },
11974 { (char *)"Magic", 0, secret_magic_list, 0, NULL },
11975 { (char *)"Sword", 0, secret_sword_list, 0, NULL },
11976 { (char *)"Misc", 0, secret_misc_list, 0, NULL },
11977 { NULL, 0, NULL, 0, NULL }
11978 };
11979
11980 static DIALOG secret_dlg[] =
11981 {
11982 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
11983 { jwin_win_proc, 0, 0, 301, 212, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
11984 { jwin_tab_proc, 6, 25, 289, 156, 0, 0, 0, 0, 0, 0, (void *) secret_tabs, NULL, (void *)secret_dlg },
11985 { jwin_button_proc, 80, 187, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
11986 { jwin_button_proc, 160, 187, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
11987 // 4
11988 { jwin_text_proc, 12, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Any Fire", NULL, NULL },
11989 { jwin_text_proc, 12, 75, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Strong Fire", NULL, NULL },
11990 { jwin_text_proc, 12, 97, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Magic Fire", NULL, NULL },
11991 { jwin_text_proc, 12, 119, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Divine Fire", NULL, NULL },
11992 //8
11993 { jwin_text_proc, 12, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Wooden Arrow", NULL, NULL },
11994 { jwin_text_proc, 12, 75, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Silver Arrow", NULL, NULL },
11995 { jwin_text_proc, 12, 97, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Golden Arrow", NULL, NULL },
11996 //11
11997 { jwin_text_proc, 12, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Bomb", NULL, NULL },
11998 { jwin_text_proc, 12, 75, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Super Bomb", NULL, NULL },
11999 //13
12000 { jwin_text_proc, 12, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Wooden Boomerang", NULL, NULL },
12001 { jwin_text_proc, 12, 75, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Magic Boomerang", NULL, NULL },
12002 { jwin_text_proc, 12, 97, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Fire Boomerang", NULL, NULL },
12003 //16
12004 { jwin_text_proc, 12, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Wand Magic", NULL, NULL },
12005 { jwin_text_proc, 12, 75, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Reflected Magic", NULL, NULL },
12006 //18
12007 { jwin_text_proc, 12, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Sword", NULL, NULL },
12008 { jwin_text_proc, 12, 75, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "White Sword", NULL, NULL },
12009 { jwin_text_proc, 12, 97, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Magic Sword", NULL, NULL },
12010 { jwin_text_proc, 12, 119, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Master Sword", NULL, NULL },
12011 { jwin_text_proc, 160, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Sword Beam", NULL, NULL },
12012 { jwin_text_proc, 160, 75, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "White Sword Beam", NULL, NULL },
12013 { jwin_text_proc, 160, 97, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Magic Sword Beam", NULL, NULL },
12014 { jwin_text_proc, 160, 119, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Master Sword Beam", NULL, NULL },
12015 //26
12016 { jwin_text_proc, 12, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Stairs", NULL, NULL },
12017 { jwin_text_proc, 12, 75, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Reflected Fireball", NULL, NULL },
12018 { jwin_text_proc, 12, 97, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Hookshot", NULL, NULL },
12019 { jwin_text_proc, 12, 119, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Wand", NULL, NULL },
12020 { jwin_text_proc, 12, 141, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Hammer", NULL, NULL },
12021 { jwin_text_proc, 12, 163, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Any Weapon", NULL, NULL },
12022 //32
12023 { jwin_ctext_proc, 235, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Flags 16-31", NULL, NULL },
12024 { jwin_text_proc, 87, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Secrets->Next (Flag only)", NULL, NULL },
12025 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 03", NULL, NULL },
12026 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 04", NULL, NULL },
12027 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 05", NULL, NULL },
12028 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 06", NULL, NULL },
12029 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 07", NULL, NULL },
12030 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 08", NULL, NULL },
12031 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 09", NULL, NULL },
12032 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 10", NULL, NULL },
12033 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 11", NULL, NULL },
12034 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 12", NULL, NULL },
12035 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 13", NULL, NULL },
12036 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 14", NULL, NULL },
12037 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 15", NULL, NULL },
12038 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 16", NULL, NULL },
12039 //48 (burn)
12040 { jwin_frame_proc, 108, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12041 { jwin_frame_proc, 108, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12042 { jwin_frame_proc, 108, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12043 { jwin_frame_proc, 108, 113, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12044 //52 (arrow)
12045 { jwin_frame_proc, 108, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12046 { jwin_frame_proc, 108, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12047 { jwin_frame_proc, 108, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12048 //55 (bomb)
12049 { jwin_frame_proc, 108, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12050 { jwin_frame_proc, 108, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12051 //57 (boomerang)
12052 { jwin_frame_proc, 108, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12053 { jwin_frame_proc, 108, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12054 { jwin_frame_proc, 108, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12055 //60 (magic)
12056 { jwin_frame_proc, 108, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12057 { jwin_frame_proc, 108, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12058 //62 (sword)
12059 { jwin_frame_proc, 108, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12060 { jwin_frame_proc, 108, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12061 { jwin_frame_proc, 108, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12062 { jwin_frame_proc, 108, 113, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12063 { jwin_frame_proc, 256, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12064 { jwin_frame_proc, 256, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12065 { jwin_frame_proc, 256, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12066 { jwin_frame_proc, 256, 113, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12067 //70 (misc)
12068 { jwin_frame_proc, 63, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12069 { jwin_frame_proc, 63, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12070 { jwin_frame_proc, 63, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12071 { jwin_frame_proc, 63, 113, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12072 { jwin_frame_proc, 63, 135, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12073 { jwin_frame_proc, 63, 157, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12074 //76 (16-32)
12075 { jwin_frame_proc, 192, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12076 { jwin_frame_proc, 214, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12077 { jwin_frame_proc, 236, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12078 { jwin_frame_proc, 258, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12079 { jwin_frame_proc, 192, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12080 { jwin_frame_proc, 214, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12081 { jwin_frame_proc, 236, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12082 { jwin_frame_proc, 258, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12083 { jwin_frame_proc, 192, 113, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12084 { jwin_frame_proc, 214, 113, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12085 { jwin_frame_proc, 236, 113, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12086 { jwin_frame_proc, 258, 113, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12087 { jwin_frame_proc, 192, 135, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12088 { jwin_frame_proc, 214, 135, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12089 { jwin_frame_proc, 236, 135, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12090 { jwin_frame_proc, 258, 135, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12091
12092 //92 (burn)
12093 { d_scombo_proc, 110, 49, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12094 { d_scombo_proc, 110, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12095 { d_scombo_proc, 110, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12096 { d_scombo_proc, 110, 115, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12097 //96 (arrow)
12098 { d_scombo_proc, 110, 49, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12099 { d_scombo_proc, 110, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12100 { d_scombo_proc, 110, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12101 //99 (bomb)
12102 { d_scombo_proc, 110, 49, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12103 { d_scombo_proc, 110, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12104 //101 (boomerang)
12105 { d_scombo_proc, 110, 49, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12106 { d_scombo_proc, 110, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12107 { d_scombo_proc, 110, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12108 //104 (magic)
12109 { d_scombo_proc, 110, 49, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12110 { d_scombo_proc, 110, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12111 //106 (sword)
12112 { d_scombo_proc, 110, 49, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12113 { d_scombo_proc, 110, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12114 { d_scombo_proc, 110, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12115 { d_scombo_proc, 110, 115, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12116 { d_scombo_proc, 258, 49, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12117 { d_scombo_proc, 258, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12118 { d_scombo_proc, 258, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12119 { d_scombo_proc, 258, 115, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12120 //114 (misc)
12121 { d_scombo_proc, 65, 49, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12122 { d_scombo_proc, 65, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12123 { d_scombo_proc, 65, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12124 { d_scombo_proc, 65, 115, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12125 { d_scombo_proc, 65, 137, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12126 { d_scombo_proc, 65, 159, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12127 //120 (16-32)
12128 { d_scombo_proc, 194, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12129 { d_scombo_proc, 216, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12130 { d_scombo_proc, 238, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12131 { d_scombo_proc, 260, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12132 { d_scombo_proc, 194, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12133 { d_scombo_proc, 216, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12134 { d_scombo_proc, 238, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12135 { d_scombo_proc, 260, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12136 { d_scombo_proc, 194, 115, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12137 { d_scombo_proc, 216, 115, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12138 { d_scombo_proc, 238, 115, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12139 { d_scombo_proc, 260, 115, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12140 { d_scombo_proc, 194, 137, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12141 { d_scombo_proc, 216, 137, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12142 { d_scombo_proc, 238, 137, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12143 { d_scombo_proc, 260, 137, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12144 //136 Secrets->Next
12145 { jwin_frame_proc, 158, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12146 { d_scombo_proc, 160, 49, 16, 16, 0, 1, 0, 0, 0, 0, NULL, NULL, NULL },
12147 //138
12148 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F1, 0, (void *) onHelp, NULL, NULL },
12149 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 'f', 0, 0, 0, (void *) onSecretF, NULL, NULL },
12150 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12151 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
12152 };
12153
12154 int32_t onSecretF()
12155 {
12156 Flags^=cFLAGS;
12157 object_message(secret_dlg+1, MSG_DRAW, 0);
12158 return D_O_K;
12159 }
12160
12161
12162 int32_t onSecretCombo()
12163 {
12164 secret_dlg[0].dp2=get_zc_font(font_lfont);
12165
12166
12167 mapscr *s;
12168
12169 if(CurrentLayer==0)
12170 {
12171 s=Map.CurrScr();
12172 }
12173 else
12174 {
12175 // s=TheMaps[(Map.CurrScr()->layermap[CurrentLayer-1]-1)*MAPSCRS+(Map.CurrScr()->layerscreen[CurrentLayer-1])];
12176 s=Map.AbsoluteScr((Map.CurrScr()->layermap[CurrentLayer-1]-1), (Map.CurrScr()->layerscreen[CurrentLayer-1]));
12177 }
12178 if(!s) return D_O_K;
12179
12180 char secretcombonumstr[27];
12181 sprintf(secretcombonumstr,"Secret Combos for Layer %d", CurrentLayer);
12182 secret_dlg[0].dp = secretcombonumstr;
12183
12184 secret_dlg[92].d1 = s->secretcombo[sBCANDLE];
12185 secret_dlg[92].fg = s->secretcset[sBCANDLE];
12186 secret_dlg[92].d2 = s->secretflag[sBCANDLE];
12187
12188 secret_dlg[93].d1 = s->secretcombo[sRCANDLE];
12189 secret_dlg[93].fg = s->secretcset[sRCANDLE];
12190 secret_dlg[93].d2 = s->secretflag[sRCANDLE];
12191
12192 secret_dlg[94].d1 = s->secretcombo[sWANDFIRE];
12193 secret_dlg[94].fg = s->secretcset[sWANDFIRE];
12194 secret_dlg[94].d2 = s->secretflag[sWANDFIRE];
12195
12196 secret_dlg[95].d1 = s->secretcombo[sDIVINEFIRE];
12197 secret_dlg[95].fg = s->secretcset[sDIVINEFIRE];
12198 secret_dlg[95].d2 = s->secretflag[sDIVINEFIRE];
12199
12200 secret_dlg[96].d1 = s->secretcombo[sARROW];
12201 secret_dlg[96].fg = s->secretcset[sARROW];
12202 secret_dlg[96].d2 = s->secretflag[sARROW];
12203
12204 secret_dlg[97].d1 = s->secretcombo[sSARROW];
12205 secret_dlg[97].fg = s->secretcset[sSARROW];
12206 secret_dlg[97].d2 = s->secretflag[sSARROW];
12207
12208 secret_dlg[98].d1 = s->secretcombo[sGARROW];
12209 secret_dlg[98].fg = s->secretcset[sGARROW];
12210 secret_dlg[98].d2 = s->secretflag[sGARROW];
12211
12212 secret_dlg[99].d1 = s->secretcombo[sBOMB];
12213 secret_dlg[99].fg = s->secretcset[sBOMB];
12214 secret_dlg[99].d2 = s->secretflag[sBOMB];
12215
12216 secret_dlg[100].d1 = s->secretcombo[sSBOMB];
12217 secret_dlg[100].fg = s->secretcset[sSBOMB];
12218 secret_dlg[100].d2 = s->secretflag[sSBOMB];
12219
12220 for(int32_t i=0; i<3; i++)
12221 {
12222 secret_dlg[101+i].d1 = s->secretcombo[sBRANG+i];
12223 secret_dlg[101+i].fg = s->secretcset[sBRANG+i];
12224 secret_dlg[101+i].d2 = s->secretflag[sBRANG+i];
12225 }
12226
12227 for(int32_t i=0; i<2; i++)
12228 {
12229 secret_dlg[104+i].d1 = s->secretcombo[sWANDMAGIC+i];
12230 secret_dlg[104+i].fg = s->secretcset[sWANDMAGIC+i];
12231 secret_dlg[104+i].d2 = s->secretflag[sWANDMAGIC+i];
12232 }
12233
12234 for(int32_t i=0; i<8; i++)
12235 {
12236 secret_dlg[106+i].d1 = s->secretcombo[sSWORD+i];
12237 secret_dlg[106+i].fg = s->secretcset[sSWORD+i];
12238 secret_dlg[106+i].d2 = s->secretflag[sSWORD+i];
12239 }
12240
12241 secret_dlg[114].d1 = s->secretcombo[sSTAIRS];
12242 secret_dlg[114].fg = s->secretcset[sSTAIRS];
12243 secret_dlg[114].d2 = s->secretflag[sSTAIRS];
12244
12245 secret_dlg[115].d1 = s->secretcombo[sREFFIREBALL];
12246 secret_dlg[115].fg = s->secretcset[sREFFIREBALL];
12247 secret_dlg[115].d2 = s->secretflag[sREFFIREBALL];
12248
12249 for(int32_t i=0; i<4; i++)
12250 {
12251 secret_dlg[116+i].d1 = s->secretcombo[sHOOKSHOT+i];
12252 secret_dlg[116+i].fg = s->secretcset[sHOOKSHOT+i];
12253 secret_dlg[116+i].d2 = s->secretflag[sHOOKSHOT+i];
12254 }
12255
12256 for(int32_t i=0; i<16; i++)
12257 {
12258 secret_dlg[120+i].d1 = s->secretcombo[sSECRET01+i];
12259 secret_dlg[120+i].fg = s->secretcset[sSECRET01+i];
12260 secret_dlg[120+i].d2 = s->secretflag[sSECRET01+i];
12261 }
12262
12263 //Sec->Next doesn't have a combo/cset value associated
12264 secret_dlg[137].d1 = 0;
12265 secret_dlg[137].fg = 0;
12266 secret_dlg[137].d2 = s->secretflag[sSECNEXT];
12267
12268 large_dialog(secret_dlg,1.75);
12269
12270 for(int32_t q = 0; secret_dlg[q].proc != NULL; ++q)
12271 {
12272 if(secret_dlg[q].proc == jwin_frame_proc)
12273 secret_dlg[q].w = secret_dlg[q].h = 36;
12274 }
12275
12276 go();
12277
12278 if(do_zqdialog(secret_dlg,3) == 2)
12279 {
12280 saved = false;
12281 s->secretcombo[sBCANDLE] = secret_dlg[92].d1;
12282 s->secretcset[sBCANDLE] = secret_dlg[92].fg;
12283 s->secretflag[sBCANDLE] = secret_dlg[92].d2;
12284
12285 s->secretcombo[sRCANDLE] = secret_dlg[93].d1;
12286 s->secretcset[sRCANDLE] = secret_dlg[93].fg;
12287 s->secretflag[sRCANDLE] = secret_dlg[93].d2;
12288
12289 s->secretcombo[sWANDFIRE] = secret_dlg[94].d1;
12290 s->secretcset[sWANDFIRE] = secret_dlg[94].fg;
12291 s->secretflag[sWANDFIRE] = secret_dlg[94].d2;
12292
12293 s->secretcombo[sDIVINEFIRE] = secret_dlg[95].d1;
12294 s->secretcset[sDIVINEFIRE] = secret_dlg[95].fg;
12295 s->secretflag[sDIVINEFIRE] = secret_dlg[95].d2;
12296
12297 s->secretcombo[sARROW] = secret_dlg[96].d1;
12298 s->secretcset[sARROW] = secret_dlg[96].fg;
12299 s->secretflag[sARROW] = secret_dlg[96].d2;
12300
12301 s->secretcombo[sSARROW] = secret_dlg[97].d1;
12302 s->secretcset[sSARROW] = secret_dlg[97].fg;
12303 s->secretflag[sSARROW] = secret_dlg[97].d2;
12304
12305 s->secretcombo[sGARROW] = secret_dlg[98].d1;
12306 s->secretcset[sGARROW] = secret_dlg[98].fg;
12307 s->secretflag[sGARROW] = secret_dlg[98].d2;
12308
12309 s->secretcombo[sBOMB] = secret_dlg[99].d1;
12310 s->secretcset[sBOMB] = secret_dlg[99].fg;
12311 s->secretflag[sBOMB] = secret_dlg[99].d2;
12312
12313 s->secretcombo[sSBOMB] = secret_dlg[100].d1;
12314 s->secretcset[sSBOMB] = secret_dlg[100].fg;
12315 s->secretflag[sSBOMB] = secret_dlg[100].d2;
12316
12317 for(int32_t i=0; i<3; i++)
12318 {
12319 s->secretcombo[sBRANG+i] = secret_dlg[101+i].d1;
12320 s->secretcset[sBRANG+i] = secret_dlg[101+i].fg;
12321 s->secretflag[sBRANG+i] = secret_dlg[101+i].d2;
12322 }
12323
12324 for(int32_t i=0; i<2; i++)
12325 {
12326 s->secretcombo[sWANDMAGIC+i] = secret_dlg[104+i].d1;
12327 s->secretcset[sWANDMAGIC+i] = secret_dlg[104+i].fg;
12328 s->secretflag[sWANDMAGIC+i] = secret_dlg[104+i].d2;
12329 }
12330
12331 for(int32_t i=0; i<8; i++)
12332 {
12333 s->secretcombo[sSWORD+i] = secret_dlg[106+i].d1;
12334 s->secretcset[sSWORD+i] = secret_dlg[106+i].fg;
12335 s->secretflag[sSWORD+i] = secret_dlg[106+i].d2;
12336 }
12337
12338 s->secretcombo[sSTAIRS] = secret_dlg[114].d1;
12339 s->secretcset[sSTAIRS] = secret_dlg[114].fg;
12340 s->secretflag[sSTAIRS] = secret_dlg[114].d2;
12341
12342 s->secretcombo[sREFFIREBALL] = secret_dlg[115].d1;
12343 s->secretcset[sREFFIREBALL] = secret_dlg[115].fg;
12344 s->secretflag[sREFFIREBALL] = secret_dlg[115].d2;
12345
12346 for(int32_t i=0; i<4; i++)
12347 {
12348 s->secretcombo[sHOOKSHOT+i] = secret_dlg[116+i].d1;
12349 s->secretcset[sHOOKSHOT+i] = secret_dlg[116+i].fg;
12350 s->secretflag[sHOOKSHOT+i] = secret_dlg[116+i].d2;
12351 }
12352
12353 for(int32_t i=0; i<16; i++)
12354 {
12355 s->secretcombo[sSECRET01+i] = secret_dlg[120+i].d1;
12356 s->secretcset[sSECRET01+i] = secret_dlg[120+i].fg;
12357 s->secretflag[sSECRET01+i] = secret_dlg[120+i].d2;
12358 }
12359 s->secretflag[sSECNEXT] = secret_dlg[137].d2;
12360
12361 }
12362
12363 comeback();
12364 return D_O_K;
12365 }
12366
12367 static DIALOG under_dlg[] =
12368 {
12369 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
12370 { jwin_win_proc, 72, 60, 176+1,120+1,vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
12371 { jwin_text_proc, 115, 83, 20, 20, vc(14), vc(1), 0, 0, 0, 0, (void *) "Current", NULL, NULL },
12372 { d_comboframe_proc, 122, 92, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12373 { d_combo_proc, 124, 94, 16, 16, 0, 0, 0, D_NOCLICK, 0, 0, NULL, NULL, NULL },
12374 { jwin_text_proc, 184, 83, 20, 20, vc(14), vc(1), 0, 0, 0, 0, (void *) "New", NULL, NULL },
12375 { d_comboframe_proc, 182, 92, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12376 { d_combo_proc, 184, 94, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12377 { jwin_button_proc, 90, 124, 61, 21, vc(14), vc(1), 's', D_EXIT, 0, 0, (void *) "&Set", NULL, NULL },
12378 { jwin_button_proc, 170, 124, 61, 21, vc(14), vc(1), 'c', D_EXIT, 0, 0, (void *) "&Cancel", NULL, NULL },
12379 { jwin_button_proc, 90, 152, 61, 21, vc(14), vc(1), 'a', D_EXIT, 0, 0, (void *) "Set &All", NULL, NULL },
12380 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F1, 0, (void *) onHelp, NULL, NULL },
12381 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12382 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
12383 };
12384
12385 int32_t onUnderCombo()
12386 {
12387 char titlebuf[64];
12388 sprintf(titlebuf, "Under Combo (Layer %d)", CurrentLayer);
12389 under_dlg[0].dp = titlebuf;
12390 under_dlg[0].dp2 = get_zc_font(font_lfont);
12391 mapscr* scr;
12392 if(CurrentLayer==0)
12393 {
12394 scr=Map.CurrScr();
12395 }
12396 else
12397 {
12398 auto map=Map.CurrScr()->layermap[CurrentLayer-1]-1;
12399 auto screen=Map.CurrScr()->layerscreen[CurrentLayer-1];
12400 scr = Map.AbsoluteScr(map,screen);
12401 }
12402 if(!scr) return D_O_K;
12403
12404 under_dlg[3].d1=scr->undercombo;
12405 under_dlg[3].fg=scr->undercset;
12406
12407 under_dlg[6].d1=Combo;
12408 under_dlg[6].fg=CSet;
12409
12410 large_dialog(under_dlg);
12411 // Doesn't place "New" and "Current" text too well
12412 under_dlg[1].x=342;
12413 under_dlg[4].x=438;
12414
12415 int32_t ret = do_zqdialog(under_dlg,-1);
12416
12417 if(ret==7)
12418 {
12419 saved=false;
12420 scr->undercombo = under_dlg[6].d1;
12421 scr->undercset = under_dlg[6].fg;
12422 }
12423
12424 if(ret==9 && jwin_alert("Confirm Overwrite","Set all Under Combos","on this map?",NULL,"&Yes","&No",'y','n',get_zc_font(font_lfont))==1)
12425 {
12426 saved=false;
12427
12428 for(int32_t i=0; i<128; i++)
12429 {
12430 Map.Scr(i)->undercombo = under_dlg[6].d1;
12431 Map.Scr(i)->undercset = under_dlg[6].fg;
12432 }
12433 }
12434
12435 return D_O_K;
12436 }
12437
12438 static DIALOG list_dlg[] =
12439 {
12440 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
12441 12 { jwin_win_proc, 60-12, 40, 200+24, 148, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
12442 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12443 12 { jwin_list_proc, 72-12-4, 60+4, 176+24+8, 92+3, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, D_EXIT, 0, 0, NULL, NULL, NULL },
12444 12 { jwin_button_proc, 90, 163, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
12445 12 { jwin_button_proc, 170, 163, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
12446 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
12447 };
12448
12449 /*
12450 typedef struct item_struct {
12451 char *s;
12452 int32_t i;
12453 } item_struct;
12454 */
12455 item_struct bii[MAXITEMS+1];
12456 int32_t bii_cnt=-1;
12457
12458 void build_bii_list(bool usenone)
12459 {
12460 int32_t start=bii_cnt=0;
12461
12462 if(usenone)
12463 {
12464 bii[0].s = (char *)"(None)";
12465 bii[0].i = -2;
12466 bii_cnt=start=1;
12467 }
12468
12469 for(int32_t i=0; i<MAXITEMS; i++)
12470 {
12471 bii[bii_cnt].s = item_string[i];
12472 bii[bii_cnt].i = i;
12473 ++bii_cnt;
12474 }
12475
12476 for(int32_t i=start; i<bii_cnt-1; i++)
12477 {
12478 for(int32_t j=i+1; j<bii_cnt; j++)
12479 {
12480 if(stricmp(bii[i].s,bii[j].s)>0 && strcmp(bii[j].s,""))
12481 {
12482 zc_swap(bii[i],bii[j]);
12483 }
12484 }
12485 }
12486 }
12487
12488
12489 const char *itemlist(int32_t index, int32_t *list_size)
12490 {
12491 if(index<0)
12492 {
12493 *list_size = bii_cnt;
12494 return NULL;
12495 }
12496
12497 return bii[index].s;
12498 }
12499 const char *itemlist_num(int32_t index, int32_t *list_size)
12500 {
12501 if(index<0)
12502 {
12503 *list_size = bii_cnt;
12504 return NULL;
12505 }
12506 static char biin_buf[64+6];
12507 if(bii[index].i < 0)
12508 return bii[index].s;
12509 sprintf(biin_buf, "%s (%03d)", bii[index].s, bii[index].i);
12510 return biin_buf;
12511 }
12512
12513 // disable items on dmaps stuff
12514 int32_t DI[MAXITEMS];
12515 int32_t nDI;
12516
12517 void initDI(int32_t index)
12518 {
12519 int32_t j=0;
12520
12521 for(int32_t i=0; i<MAXITEMS; i++)
12522 {
12523 int32_t index1=bii[i].i; // true index of item in dmap's DI list
12524
12525 if(DMaps[index].disableditems[index1])
12526 {
12527 DI[j]=i;
12528 j++;
12529 }
12530 }
12531
12532 nDI=j;
12533
12534 for(int32_t i=j; i<MAXITEMS; i++) DI[j]=0;
12535
12536 return;
12537 }
12538
12539 void insertDI(int32_t id, int32_t index)
12540 {
12541 int32_t trueid=bii[id].i;
12542 DMaps[index].disableditems[trueid] |= 1; //bit set
12543 initDI(index);
12544 return;
12545 }
12546
12547 void deleteDI(int32_t id, int32_t index)
12548 {
12549 int32_t i=DI[id];
12550 int32_t trueid=bii[i].i;
12551 DMaps[index].disableditems[trueid] &= (~1); // bit clear
12552 initDI(index);
12553 return;
12554 }
12555
12556 const char *DIlist(int32_t index, int32_t *list_size)
12557 {
12558 if(index<0)
12559 {
12560 *list_size = nDI;
12561 return NULL;
12562 }
12563
12564 int32_t i=DI[index];
12565 return bii[i].s;
12566
12567 }
12568
12569 weapon_struct biw[MAXWPNS];
12570 int32_t biw_cnt=-1;
12571
12572 void build_biw_list()
12573 {
12574 int32_t start=biw_cnt=0;
12575
12576 for(int32_t i=start; i<MAXWPNS; i++)
12577 {
12578 biw[biw_cnt].s = (char *)weapon_string[i];
12579 biw[biw_cnt].i = i;
12580 ++biw_cnt;
12581 }
12582
12583 for(int32_t i=start; i<biw_cnt-1; i++)
12584 {
12585 for(int32_t j=i+1; j<biw_cnt; j++)
12586 if(stricmp(biw[i].s,biw[j].s)>0 && strcmp(biw[j].s,""))
12587 zc_swap(biw[i],biw[j]);
12588 }
12589 }
12590
12591 const char *weaponlist(int32_t index, int32_t *list_size)
12592 {
12593 if(index<0)
12594 {
12595 *list_size = biw_cnt;
12596 return NULL;
12597 }
12598
12599 return biw[index].s;
12600 }
12601 const char *weaponlist_num(int32_t index, int32_t *list_size)
12602 {
12603 if(index<0)
12604 {
12605 *list_size = biw_cnt;
12606 return NULL;
12607 }
12608 static char biwn_buf[64+6];
12609 if(biw[index].i < 0)
12610 return biw[index].s;
12611 sprintf(biwn_buf, "%s (%03d)", biw[index].s, biw[index].i);
12612 return biwn_buf;
12613 }
12614 int32_t writeoneweapon(PACKFILE *f, int32_t index)
12615 {
12616 dword section_version=V_WEAPONS;
12617 int32_t zversion = ZELDA_VERSION;
12618 int32_t zbuild = VERSION_BUILD;
12619 int32_t iid = biw[index].i;
12620 al_trace("Writing Weapon Sprite .zwpnspr file for weapon id: %d\n", iid);
12621
12622 //section version info
12623 if(!p_iputl(zversion,f))
12624 {
12625 return 0;
12626 }
12627 if(!p_iputl(zbuild,f))
12628 {
12629 return 0;
12630 }
12631 if(!p_iputw(section_version,f))
12632 {
12633 return 0;
12634 }
12635
12636 if(!write_deprecated_section_cversion(section_version, f))
12637 {
12638 return 0;
12639 }
12640
12641 //weapon string
12642
12643 if(!pfwrite((char *)weapon_string[iid], 64, f))
12644 {
12645 return 0;
12646 }
12647
12648 if(!p_putc(wpnsbuf[iid].misc,f))
12649 {
12650 return 0;
12651 }
12652
12653 if(!p_putc(wpnsbuf[iid].csets,f))
12654 {
12655 return 0;
12656 }
12657
12658 if(!p_putc(wpnsbuf[iid].frames,f))
12659 {
12660 return 0;
12661 }
12662
12663 if(!p_putc(wpnsbuf[iid].speed,f))
12664 {
12665 return 0;
12666 }
12667
12668 if(!p_putc(wpnsbuf[iid].type,f))
12669 {
12670 return 0;
12671 }
12672
12673 if(!p_iputw(wpnsbuf[iid].script,f))
12674 {
12675 return 0;
12676 }
12677
12678 //2.55 starts here
12679 if(!p_iputl(wpnsbuf[iid].tile,f))
12680 {
12681 return 0;
12682 }
12683
12684 return 1;
12685 }
12686
12687
12688 int32_t readoneweapon(PACKFILE *f, int32_t index)
12689 {
12690 dword section_version = 0;
12691 int32_t zversion = 0;
12692 int32_t zbuild = 0;
12693 wpndata tempwpnspr;
12694 memset(&tempwpnspr, 0, sizeof(wpndata));
12695
12696
12697 //char dmapstring[64]={0};
12698 //section version info
12699 if(!p_igetl(&zversion,f))
12700 {
12701 return 0;
12702 }
12703 if(!p_igetl(&zbuild,f))
12704 {
12705 return 0;
12706 }
12707 if(!p_igetw(&section_version,f))
12708 {
12709 return 0;
12710 }
12711 if(!read_deprecated_section_cversion(f))
12712 {
12713 return 0;
12714 }
12715 al_trace("readoneweapon section_version: %d\n", section_version);
12716
12717 if ( zversion > ZELDA_VERSION )
12718 {
12719 al_trace("Cannot read .zwpnspr packfile made in ZC version (%x) in this version of ZC (%x)\n", zversion, ZELDA_VERSION);
12720 return 0;
12721 }
12722
12723 else if ( ( section_version > V_WEAPONS ) )
12724 {
12725 al_trace("Cannot read .zwpnspr packfile made using V_WEAPONS (%d)\n", section_version);
12726 return 0;
12727
12728 }
12729 else
12730 {
12731 al_trace("Reading a .zwpnspr packfile made in ZC Version: %x, Build: %d\n", zversion, zbuild);
12732 }
12733
12734 char tmp_wpn_name[64];
12735 memset(tmp_wpn_name,0,64);
12736 if(!pfread(&tmp_wpn_name, 64, f))
12737 {
12738 return 0;
12739 }
12740
12741 word oldtile = 0;
12742 if(section_version < 8)
12743 if(!p_igetw(&oldtile,f))
12744 return 0;
12745
12746 if(!p_getc(&tempwpnspr.misc,f))
12747 {
12748 return 0;
12749 }
12750
12751 if(!p_getc(&tempwpnspr.csets,f))
12752 {
12753 return 0;
12754 }
12755
12756 if(!p_getc(&tempwpnspr.frames,f))
12757 {
12758 return 0;
12759 }
12760
12761 if(!p_getc(&tempwpnspr.speed,f))
12762 {
12763 return 0;
12764 }
12765
12766 if(!p_getc(&tempwpnspr.type,f))
12767 {
12768 return 0;
12769 }
12770
12771 if(!p_igetw(&tempwpnspr.script,f))
12772 {
12773 return 0;
12774 }
12775
12776 //2.55 starts here
12777 if ( zversion >= 0x255 )
12778 {
12779 if ( section_version >= 7 )
12780 {
12781 if(!p_igetl(&tempwpnspr.tile,f))
12782 {
12783 return 0;
12784 }
12785 }
12786 }
12787 if ( zversion < 0x255 )
12788 {
12789 tempwpnspr.tile = oldtile;
12790 }
12791 ::memcpy( &(wpnsbuf[biw[index].i]),&tempwpnspr, sizeof(wpndata));
12792 ::memcpy(weapon_string[biw[index].i], tmp_wpn_name, 64);
12793
12794 return 1;
12795 }
12796
12797 static int32_t seldata_copy;
12798 static void (*seldata_paste_func)(int32_t, int32_t);
12799
12800 void seldata_rclick_func(int32_t index, int32_t x, int32_t y)
12801 {
12802 NewMenu rcmenu {
12803 { "&Copy", [&](){seldata_copy = index;} },
12804 { "Paste", "&v", [&]()
12805 {
12806 seldata_paste_func(seldata_copy, index);
12807 saved = false;
12808 }, 0, seldata_copy < 0 ? MFL_DIS : 0 },
12809 };
12810 rcmenu.pop(x, y);
12811 }
12812
12813 int32_t select_data(const char *prompt,int32_t index,const char *(proc)(int32_t,int32_t*), FONT *title_font, void (*copyFunc)(int32_t, int32_t))
12814 {
12815 if(proc==NULL)
12816 return -1;
12817
12818 list_dlg[0].dp=(void *)prompt;
12819 list_dlg[0].dp2=title_font;
12820 list_dlg[2].d1=index;
12821 ListData select_list(proc, &font);
12822 list_dlg[2].dp=(void *) &select_list;
12823
12824 large_dialog(list_dlg);
12825
12826 seldata_copy=-1;
12827 seldata_paste_func=copyFunc;
12828 if(copyFunc)
12829 {
12830 list_dlg[2].flags|=D_USER<<1;
12831 list_dlg[2].dp3=(void*)seldata_rclick_func;
12832 }
12833 else
12834 {
12835 list_dlg[2].flags&=~(D_USER<<1);
12836 list_dlg[2].dp3=0;
12837 }
12838
12839 int32_t ret=do_zqdialog(list_dlg,2);
12840
12841 if(ret==0||ret==4)
12842 {
12843 position_mouse_z(0);
12844 return -1;
12845 }
12846
12847 return list_dlg[2].d1;
12848 }
12849
12850 int32_t select_data(const char *prompt,int32_t index,const char *(proc)(int32_t,int32_t*), const char *b1, const char *b2, FONT *title_font, void (*copyFunc)(int32_t, int32_t))
12851 {
12852 if(proc==NULL)
12853 return -1;
12854
12855 list_dlg[0].dp=(void *)prompt;
12856 list_dlg[0].dp2=title_font;
12857 list_dlg[2].d1=index;
12858 ListData select_data_list(proc, &font);
12859 list_dlg[2].dp=(void *) &select_data_list;
12860 list_dlg[3].dp=(void *)b1;
12861 list_dlg[4].dp=(void *)b2;
12862
12863 large_dialog(list_dlg);
12864
12865 seldata_copy=-1;
12866 seldata_paste_func=copyFunc;
12867 if(copyFunc)
12868 {
12869 list_dlg[2].flags|=D_USER<<1;
12870 list_dlg[2].dp3=(void*)seldata_rclick_func;
12871 }
12872 else
12873 {
12874 list_dlg[2].flags&=~(D_USER<<1);
12875 list_dlg[2].dp3=0;
12876 }
12877
12878 int32_t ret = do_zqdialog(list_dlg,2);
12879 list_dlg[3].dp=(void *) "OK";
12880 list_dlg[4].dp=(void *) "Cancel";
12881
12882 if(ret==0||ret==4)
12883 {
12884 position_mouse_z(0);
12885 return -1;
12886 }
12887
12888 position_mouse_z(0);
12889 return list_dlg[2].d1;
12890 }
12891
12892 static char sfx_str_buf[42];
12893
12894 const char *sfxlist(int32_t index, int32_t *list_size)
12895 {
12896 if(index>=0)
12897 {
12898 bound(index,0,WAV_COUNT-1);
12899 sprintf(sfx_str_buf,"%d: %s",index, index ? sfx_string[index] : "(None)");
12900 return sfx_str_buf;
12901 }
12902
12903 *list_size=WAV_COUNT;
12904 return NULL;
12905 }
12906
12907 12 static ListData sfx_list(sfxlist, &font);
12908
12909 const char *screenscriptdroplist(int32_t index, int32_t *list_size)
12910 {
12911 if(index<0)
12912 {
12913 *list_size = biscreens_cnt;
12914 return NULL;
12915 }
12916
12917 return biscreens[index].first.c_str();
12918 }
12919
12920 //droplist like the dialog proc, naming scheme for this stuff is awful...
12921 12 static ListData screenscript_list(screenscriptdroplist, &a4fonts[font_pfont]);
12922
12923 int32_t onScreenScript()
12924 {
12925 call_screendata_dialog(7);
12926 return D_O_K;
12927 }
12928
12929 int32_t onScrData()
12930 {
12931 restore_mouse();
12932 call_screendata_dialog();
12933 return D_O_K;
12934 }
12935
12936 const char *roomslist(int32_t index, int32_t *list_size)
12937 {
12938 if(index>=0)
12939 {
12940 if(index>=MAXROOMTYPES)
12941 index=MAXROOMTYPES-1;
12942
12943 return roomtype_string[index];
12944 }
12945
12946 *list_size=MAXROOMTYPES;
12947 return NULL;
12948 }
12949
12950 static char number_str_buf[MIDI_TRACK_BUFFER_SIZE];
12951 int32_t number_list_size=1;
12952 bool number_list_zero=false;
12953
12954 const char *numberlist(int32_t index, int32_t *list_size)
12955 {
12956 if(index>=0)
12957 {
12958 bound(index,0,number_list_size-1);
12959 sprintf(number_str_buf,"%d",index+(number_list_zero?0:1));
12960 return number_str_buf;
12961 }
12962
12963 *list_size=number_list_size;
12964 return NULL;
12965 }
12966
12967 static char dmap_str_buf[37];
12968 int32_t dmap_list_size=MAXDMAPS;
12969 bool dmap_list_zero=true;
12970
12971 const char *dmaplist(int32_t index, int32_t *list_size)
12972 {
12973 if(index>=0)
12974 {
12975 bound(index,0,dmap_list_size-1);
12976 sprintf(dmap_str_buf,"%3d-%s",index+(dmap_list_zero?0:1), DMaps[index].name);
12977 return dmap_str_buf;
12978 }
12979
12980 *list_size=dmap_list_size;
12981 return NULL;
12982 }
12983
12984 char *hexnumlist(int32_t index, int32_t *list_size)
12985 {
12986 if(index>=0)
12987 {
12988 bound(index,0,number_list_size-1);
12989 sprintf(number_str_buf,"%X",index+(number_list_zero?0:1));
12990 return number_str_buf;
12991 }
12992
12993 *list_size=number_list_size;
12994 return NULL;
12995 }
12996
12997 const char *maplist(int32_t index, int32_t *list_size)
12998 {
12999 if(index>=0)
13000 {
13001 bound(index,0,MAXMAPS-1);
13002 sprintf(number_str_buf,"%d",index+1);
13003 return number_str_buf;
13004 }
13005
13006 *list_size=MAXMAPS;
13007 return NULL;
13008 }
13009
13010 const char *gotomaplist(int32_t index, int32_t *list_size)
13011 {
13012 if(index>=0)
13013 {
13014 bound(index,0,map_count-1);
13015 sprintf(number_str_buf,"%d",index+1);
13016 return number_str_buf;
13017 }
13018
13019 *list_size = map_count;
13020 return NULL;
13021 }
13022
13023 const char *midilist(int32_t index, int32_t *list_size)
13024 {
13025 if(index>=0)
13026
13027 {
13028 bound(index,0,MAXCUSTOMMIDIS_ZQ-1);
13029 return midi_string[index];
13030 }
13031
13032 *list_size=MAXCUSTOMMIDIS_ZQ;
13033 return NULL;
13034 }
13035
13036 const char *custommidilist(int32_t index, int32_t *list_size)
13037 {
13038 if(index>=0)
13039 {
13040 bound(index,0,MAXCUSTOMMIDIS_ZQ-1);
13041 sprintf(number_str_buf,"%3d - %s",index+(number_list_zero?0:1),customtunes[index].data?customtunes[index].title:"(Empty)");
13042 return number_str_buf;
13043 }
13044
13045 *list_size=number_list_size;
13046 return NULL;
13047 }
13048
13049 const char *enhancedmusiclist(int32_t index, int32_t *list_size)
13050 {
13051 index=index; //this is here to prevent unused parameter warnings
13052 list_size=list_size; //this is here to prevent unused parameter warnings
13053 /*if(index>=0)
13054 {
13055 bound(index,0,MAXMUSIC-1);
13056 sprintf(number_str_buf,"%3d - %s",index+(number_list_zero?0:1),enhancedMusic[index].filename[0]?enhancedMusic[index].title:"(Empty)" );
13057 return number_str_buf;
13058 }
13059 *list_size=number_list_size;*/
13060 return NULL;
13061 }
13062
13063
13064 const char *levelnumlist(int32_t index, int32_t *list_size)
13065 {
13066 if(index>=0)
13067 {
13068 bound(index,0,0xFFF);
13069 sprintf(number_str_buf,"%.3X - %s",index,palnames[index]);
13070 return number_str_buf;
13071 }
13072
13073 *list_size=MAXLEVELS;
13074 return NULL;
13075 }
13076
13077 static char shop_str_buf[40];
13078 int32_t shop_list_size=1;
13079
13080 const char *shoplist(int32_t index, int32_t *list_size)
13081 {
13082 if(index>=0)
13083 {
13084 bound(index,0,shop_list_size-1);
13085 sprintf(shop_str_buf,"%3d: %s",index,QMisc.shop[index].name);
13086 return shop_str_buf;
13087 }
13088
13089 *list_size=shop_list_size;
13090 return NULL;
13091 }
13092
13093 static char bottle_str_buf[40];
13094 int32_t bottle_list_size=1;
13095
13096 const char *bottlelist(int32_t index, int32_t *list_size)
13097 {
13098 if(index>=0)
13099 {
13100 bound(index,0,bottle_list_size-1);
13101 sprintf(bottle_str_buf,"%2d: %s",index+1,QMisc.bottle_types[index].name);
13102 return bottle_str_buf;
13103 }
13104
13105 *list_size=bottle_list_size;
13106 return NULL;
13107 }
13108
13109 static char bottleshop_str_buf[40];
13110 int32_t bottleshop_list_size=1;
13111
13112 const char *bottleshoplist(int32_t index, int32_t *list_size)
13113 {
13114 if(index>=0)
13115 {
13116 bound(index,0,bottleshop_list_size-1);
13117 sprintf(bottleshop_str_buf,"%3d: %s",index,QMisc.bottle_shop_types[index].name);
13118 return bottleshop_str_buf;
13119 }
13120
13121 *list_size=bottleshop_list_size;
13122 return NULL;
13123 }
13124
13125 static char info_str_buf[40];
13126 int32_t info_list_size=1;
13127
13128 const char *infolist(int32_t index, int32_t *list_size)
13129 {
13130 if(index>=0)
13131 {
13132 bound(index,0,info_list_size-1);
13133 sprintf(info_str_buf,"%3d: %s",index,QMisc.info[index].name);
13134 return info_str_buf;
13135 }
13136
13137 *list_size=info_list_size;
13138 return NULL;
13139 }
13140
13141 bool mapcount_will_affect_layers(word newmapcount)
13142 {
13143 for(int32_t i=0; i<(newmapcount)*MAPSCRS; i++)
13144 {
13145 mapscr *layerchecker=&TheMaps[i];
13146
13147 for(int32_t j=0; j<6; j++)
13148 {
13149 if(layerchecker->layermap[j]>(newmapcount))
13150 {
13151 return true;
13152 }
13153 }
13154 }
13155 return false;
13156 }
13157
13158 void update_map_count(word newmapcount)
13159 {
13160 if(map_count == newmapcount) return;
13161 saved = false;
13162 setMapCount2(newmapcount);
13163 //Prevent the nine 'last mapscreen' buttons from pointing to invlid locations
13164 //if the user reduces the mapcount. -Z ( 23rd September, 2019 )
13165 for ( int32_t q = 0; q < 9; q++ )
13166 {
13167 map_page[q].map = ( map_page[q].map > newmapcount-1 ) ? newmapcount-1 : map_page[q].map;
13168 }
13169 for(int32_t i=0; i<(newmapcount)*MAPSCRS; i++)
13170 {
13171 fix_layers(&TheMaps[i], false);
13172 }
13173
13174 refresh(rMAP+rSCRMAP+rMENU);
13175 }
13176
13177 int32_t onGotoMap()
13178 {
13179 int32_t ret = select_data("Goto Map",Map.getCurrMap(),gotomaplist,get_zc_font(font_lfont));
13180
13181 if(ret >= 0)
13182 {
13183 int32_t m=Map.getCurrMap();
13184 Map.setCurrMap(ret);
13185 }
13186
13187 refresh(rALL);
13188 return D_O_K;
13189 }
13190
13191 int32_t onFlags()
13192 {
13193 restore_mouse();
13194 int32_t ret=select_cflag("Select Combo Flag",Flag);
13195 position_mouse_z(0);
13196
13197 if(ret>=0)
13198 {
13199 Flag=ret;
13200 refresh(rMENU);
13201 doflags();
13202 }
13203
13204 return D_O_K;
13205 }
13206
13207 static DIALOG usedcombo_list_dlg[] =
13208 {
13209 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
13210 12 { jwin_win_proc, 60-12, 40, 200+24, 148, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Combos Used", NULL, NULL },
13211 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
13212 12 { jwin_textbox_proc, 72-12, 60+4, 176+24+1, 92+4, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, D_EXIT, 0, 0, NULL, NULL, NULL },
13213 12 { jwin_button_proc, 130, 163, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
13214 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
13215 };
13216
13217
13218
13219 int32_t onUsedCombos()
13220 {
13221 restore_mouse();
13222 usedcombo_list_dlg[0].dp2=get_zc_font(font_lfont);
13223
13224 int32_t usedcombos[7][300][2];
13225 char combolist_text[65536];
13226 char temptext[80];
13227
13228 int32_t drawmap=Map.getCurrMap();
13229 int32_t drawscr=Map.getCurrScr();
13230 int32_t counter[7];
13231
13232 for(int32_t layer=0; layer<7; ++layer)
13233 {
13234 counter[layer]=0;
13235
13236 if(layer==0)
13237 {
13238 drawmap=Map.getCurrMap();
13239 drawscr=Map.getCurrScr();
13240 }
13241 else
13242 {
13243 drawmap=Map.CurrScr()->layermap[layer-1]-1;
13244 drawscr=Map.CurrScr()->layerscreen[layer-1];
13245 }
13246 mapscr* draw_mapscr = Map.AbsoluteScr(drawmap, drawscr);
13247 if(!draw_mapscr) continue;
13248
13249 usedcombos[layer][0][0]=draw_mapscr->data[0];
13250 usedcombos[layer][0][1]=1;
13251 counter[layer]=1;
13252
13253 for(int32_t i=1; i<176; ++i)
13254 {
13255 bool used=false;
13256
13257 for(int32_t j=0; j<counter[layer]; ++j)
13258 {
13259 if(usedcombos[layer][j][0]==draw_mapscr->data[i])
13260 {
13261 ++usedcombos[layer][j][1];
13262 used=true;
13263 break;
13264 }
13265 }
13266
13267 if(!used)
13268 {
13269 usedcombos[layer][counter[layer]][0]=draw_mapscr->data[i];
13270 usedcombos[layer][counter[layer]][1]=1;
13271 ++counter[layer];
13272 }
13273 }
13274
13275 for(int32_t i=0; i<counter[layer]-1; i++)
13276 {
13277 for(int32_t j=i+1; j<counter[layer]; j++)
13278 {
13279 if(usedcombos[layer][i][0]>usedcombos[layer][j][0])
13280 {
13281 zc_swap(usedcombos[layer][i][0],usedcombos[layer][j][0]);
13282 zc_swap(usedcombos[layer][i][1],usedcombos[layer][j][1]);
13283 }
13284 }
13285 }
13286 }
13287
13288 sprintf(combolist_text, " ");
13289
13290 for(int32_t layer=0; layer<7; ++layer)
13291 {
13292 if(counter[layer]>0)
13293 {
13294 if(layer>0)
13295 {
13296 strcat(combolist_text, "\n");
13297 }
13298
13299 sprintf(temptext, "Combos on layer %d\n-----------------\n", layer);
13300 strcat(combolist_text, temptext);
13301
13302 for(int32_t i=0; i<counter[layer]; i++)
13303 {
13304 if((i<counter[layer]-1) && (((usedcombos[layer][i][1]==usedcombos[layer][i+1][1]&&(usedcombos[layer][i][0]+1==usedcombos[layer][i+1][0])) && ((i==0) || ((usedcombos[layer][i][1]!=usedcombos[layer][i-1][1])||((usedcombos[layer][i][0]-1!=usedcombos[layer][i-1][0])))))))
13305 {
13306 sprintf(temptext, "%5d ", usedcombos[layer][i][0]);
13307 strcat(combolist_text, temptext);
13308 }
13309 else if(((i>0) && (((usedcombos[layer][i][1]==usedcombos[layer][i-1][1])&&((usedcombos[layer][i][0]-1==usedcombos[layer][i-1][0]))) && ((i==counter[layer]-1) || ((usedcombos[layer][i][1]!=usedcombos[layer][i+1][1])||((usedcombos[layer][i][0]+1!=usedcombos[layer][i+1][0])))))))
13310 {
13311 sprintf(temptext, "- %5d (%3d)\n", usedcombos[layer][i][0],usedcombos[layer][i][1]);
13312 strcat(combolist_text, temptext);
13313 }
13314 else if(((i==0) && ((usedcombos[layer][i][1]!=usedcombos[layer][i+1][1])||((usedcombos[layer][i][0]+1!=usedcombos[layer][i+1][0]))))||
13315 ((i==counter[layer]-1) && ((usedcombos[layer][i][1]!=usedcombos[layer][i-1][1])||((usedcombos[layer][i][0]-1!=usedcombos[layer][i-1][0]))))||
13316 ((i>0) && (i<counter[layer]-1) && ((usedcombos[layer][i][1]!=usedcombos[layer][i+1][1])||((usedcombos[layer][i][0]+1!=usedcombos[layer][i+1][0]))) && ((usedcombos[layer][i][1]!=usedcombos[layer][i-1][1])||((usedcombos[layer][i][0]-1!=usedcombos[layer][i-1][0])))))
13317 {
13318 sprintf(temptext, " %5d (%3d)\n", usedcombos[layer][i][0],usedcombos[layer][i][1]);
13319 strcat(combolist_text, temptext);
13320 }
13321 }
13322 }
13323 }
13324
13325 strcat(combolist_text, "\n");
13326 usedcombo_list_dlg[2].dp=combolist_text;
13327 usedcombo_list_dlg[2].d2=0;
13328
13329 large_dialog(usedcombo_list_dlg);
13330
13331 do_zqdialog(usedcombo_list_dlg,2);
13332 position_mouse_z(0);
13333 return D_O_K;
13334 }
13335
13336 int32_t onItem()
13337 {
13338 restore_mouse();
13339 int32_t exit_status;
13340 int32_t current_item=Map.CurrScr()->hasitem != 0 ? Map.CurrScr()->item : -1;
13341
13342 ItemListerDialog(current_item,true).show();
13343 if(current_item != lister_sel_val)
13344 {
13345 if(lister_sel_val>=0)
13346 {
13347 saved = false;
13348 Map.CurrScr()->item = lister_sel_val;
13349 Map.CurrScr()->hasitem = true;
13350 }
13351 else
13352 {
13353 saved = false;
13354 Map.CurrScr()->hasitem = false;
13355 }
13356 }
13357
13358 refresh(rMAP+rMENU);
13359 return D_O_K;
13360 }
13361
13362 void call_room_dlg(mapscr* scr);
13363 int32_t onRoom()
13364 {
13365 restore_mouse();
13366 auto* scr = Map.CurrScr();
13367 call_room_dlg(scr);
13368
13369 refresh(rMAP+rMENU);
13370 return D_O_K;
13371 }
13372
13373 int32_t onEndString()
13374 {
13375 int32_t ret=select_data("Select Ending String",QMisc.endstring,msgslist,get_zc_font(font_lfont));
13376
13377 if(ret>=0)
13378 {
13379 saved=false;
13380 QMisc.endstring=msglistcache[ret];
13381 }
13382
13383 refresh(rMENU);
13384 return D_O_K;
13385 }
13386
13387 12 static ListData levelnum_list(levelnumlist, &font);
13388
13389 static DIALOG screen_pal_dlg[] =
13390 {
13391 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
13392 12 { jwin_win_proc, 60-12, 40, 200-16, 96, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Select Palette", NULL, NULL },
13393 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
13394 12 { jwin_droplist_proc, 72-12, 84+4, 161, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, D_EXIT, 0, 0, (void *) &levelnum_list, NULL, NULL },
13395 12 { jwin_button_proc, 70, 111, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
13396 12 { jwin_button_proc, 150, 111, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
13397 12 { jwin_text_proc, 72-12, 60+4, 168, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Note: This does not affect how the", NULL, NULL },
13398 12 { jwin_text_proc, 72-12, 72+4, 168, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "room will be displayed in-game!", NULL, NULL },
13399 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
13400 };
13401 // return list_dlg[2].d1;
13402
13403 int32_t onScreenPalette()
13404 {
13405 restore_mouse();
13406 screen_pal_dlg[0].dp2=get_zc_font(font_lfont);
13407 auto oldcol = screen_pal_dlg[2].d1 = Map.getcolor();
13408
13409 large_dialog(screen_pal_dlg);
13410 auto old_valid = Map.CurrScr()->valid;
13411 pause_dlg_tint(true);
13412 zq_set_screen_never_freeze(true);
13413 while(true)
13414 {
13415 auto ret = do_zqdialog(screen_pal_dlg,2);
13416 if(ret == 2)
13417 {
13418 Map.setcolor(screen_pal_dlg[2].d1);
13419 refresh(rALL);
13420 }
13421 else
13422 {
13423 if(ret == 3)
13424 {
13425 if(screen_pal_dlg[2].d1 != oldcol)
13426 saved=false;
13427 Map.setcolor(screen_pal_dlg[2].d1);
13428 }
13429 else
13430 {
13431 Map.setcolor(oldcol);
13432 Map.CurrScr()->valid = old_valid;
13433 }
13434 refresh(rALL);
13435 break;
13436 }
13437 }
13438 pause_dlg_tint(false);
13439 zq_set_screen_never_freeze(false);
13440
13441 rebuild_trans_table();
13442
13443 return D_O_K;
13444 }
13445
13446 int32_t onDecScrPal()
13447 {
13448 if(DisableLPalShortcuts)
13449 {
13450 lpal_dsa();
13451 return D_O_K;
13452 }
13453 restore_mouse();
13454 int32_t c = Map.getcolor();
13455 c = (c+511) % 512;
13456 Map.setcolor(c);
13457 refresh(rALL);
13458 saved = false;
13459 return D_O_K;
13460 }
13461
13462 int32_t onIncScrPal()
13463 {
13464 if(DisableLPalShortcuts)
13465 {
13466 lpal_dsa();
13467 return D_O_K;
13468 }
13469 restore_mouse();
13470 int32_t c = Map.getcolor();
13471 c = (c+1)%512;
13472 Map.setcolor(c);
13473 refresh(rALL);
13474 saved = false;
13475 return D_O_K;
13476 }
13477
13478 int32_t PalWrap(int32_t kX, int32_t const kLowerBound, int32_t const kUpperBound)
13479 {
13480 int32_t range_size = kUpperBound - kLowerBound + 1;
13481
13482 if (kX < kLowerBound)
13483 kX += range_size * ((kLowerBound - kX) / range_size + 1);
13484
13485 return kLowerBound + (kX - kLowerBound) % range_size;
13486 }
13487
13488 int32_t onDecScrPal16()
13489 {
13490 if(DisableLPalShortcuts)
13491 {
13492 lpal_dsa();
13493 return D_O_K;
13494 }
13495 restore_mouse();
13496 int32_t c = Map.getcolor();
13497 c = PalWrap( ( c-0x10 ), 0, 511 );
13498 Map.setcolor(c);
13499 refresh(rALL);
13500 saved = false;
13501 return D_O_K;
13502 }
13503
13504 int32_t onIncScrPal16()
13505 {
13506 if(DisableLPalShortcuts)
13507 {
13508 lpal_dsa();
13509 return D_O_K;
13510 }
13511 restore_mouse();
13512 int32_t c = Map.getcolor();
13513 c = PalWrap( ( c+0x10 ), 0, 511 );
13514 Map.setcolor(c);
13515 refresh(rALL);
13516 saved = false;
13517 return D_O_K;
13518 }
13519
13520 int32_t onZoomIn()
13521 {
13522 change_mapscr_zoom(-1);
13523 return D_O_K;
13524 }
13525
13526 int32_t onZoomOut()
13527 {
13528 change_mapscr_zoom(1);
13529 return D_O_K;
13530 }
13531
13532 int32_t d_ndroplist_proc(int32_t msg,DIALOG *d,int32_t c)
13533 {
13534 int32_t ret = jwin_droplist_proc(msg,d,c);
13535
13536 // The only place this proc is used is in the info type editor.
13537 // If it's ever used anywhere else, this will probably need to be changed.
13538 // Maybe add a flag for it or something.
13539 int32_t msgID=msg_at_pos(d->d1);
13540
13541 switch(msg)
13542 {
13543 case MSG_DRAW:
13544 case MSG_CHAR:
13545 case MSG_CLICK:
13546 textprintf_ex(screen,font,d->x - 48,d->y + 4,jwin_pal[jcBOXFG],jwin_pal[jcBOX],"%5d",msgID);
13547 }
13548
13549 return ret;
13550 }
13551
13552 int32_t d_idroplist_proc(int32_t msg,DIALOG *d,int32_t c)
13553 {
13554 int32_t ret = jwin_droplist_proc(msg,d,c);
13555
13556 switch(msg)
13557 {
13558 case MSG_DRAW:
13559 case MSG_CHAR:
13560 case MSG_CLICK:
13561 int32_t tile = bii[d->d1].i >=0 ? itemsbuf[bii[d->d1].i].tile : 0;
13562 int32_t cset = bii[d->d1].i >=0 ? itemsbuf[bii[d->d1].i].csets&15 : 0;
13563 int32_t x = d->x + d->w + 4;
13564 int32_t y = d->y - 8;
13565 int32_t w = 32;
13566 int32_t h = 32;
13567
13568 BITMAP *buf = create_bitmap_ex(8,16,16);
13569 BITMAP *bigbmp = create_bitmap_ex(8,w,h);
13570
13571 if(buf && bigbmp)
13572 {
13573 clear_bitmap(buf);
13574
13575 if(tile)
13576 overtile16(buf, tile,0,0,cset,0);
13577
13578 stretch_blit(buf, bigbmp, 0,0, 16, 16, 0, 0, w, h);
13579 destroy_bitmap(buf);
13580 jwin_draw_frame(screen,x,y,w+4,h+4,FR_DEEP);
13581 blit(bigbmp,screen,0,0,x+2,y+2,w,h);
13582 destroy_bitmap(bigbmp);
13583 }
13584
13585 }
13586
13587 return ret;
13588 }
13589
13590 int32_t d_nidroplist_proc(int32_t msg,DIALOG *d,int32_t c)
13591 {
13592 int32_t ret = d_idroplist_proc(msg,d,c);
13593
13594 switch(msg)
13595 {
13596 case MSG_DRAW:
13597 case MSG_CHAR:
13598 case MSG_CLICK:
13599 textprintf_ex(screen,font,d->x - 48,d->y + 4,jwin_pal[jcBOXFG],jwin_pal[jcBOX],"%5d",bii[d->d1].i);
13600 }
13601
13602 return ret;
13603 }
13604
13605 // Triforce pieces
13606 static byte triframe_points[9*4] =
13607 {
13608 0,2,2,0, 2,0,4,2, 0,2,4,2, 1,1,3,1, 2,0,2,2,
13609 1,1,1,2, 1,1,2,2, 3,1,3,2, 3,1,2,2
13610 };
13611
13612 int32_t d_tri_frame_proc(int32_t msg,DIALOG *d,int32_t c)
13613 {
13614 //these are here to bypass compiler warnings about unused arguments
13615 c=c;
13616
13617 if(msg==MSG_DRAW)
13618 {
13619 int32_t x[5],y[3];
13620
13621 x[0]=d->x;
13622 x[1]=d->x+(d->w>>2);
13623 x[2]=d->x+(d->w>>1);
13624 x[3]=d->x+(d->w>>1)+(d->w>>2);
13625 x[4]=d->x+d->w;
13626 y[0]=d->y;
13627 y[1]=d->y+(d->h>>1);
13628 y[2]=d->y+d->h;
13629
13630 byte *p = triframe_points;
13631
13632 for(int32_t i=0; i<9; i++)
13633 {
13634 line(screen,x[*p],y[*(p+1)],x[*(p+2)],y[*(p+3)],d->fg);
13635 p+=4;
13636 }
13637 }
13638
13639 return D_O_K;
13640 }
13641
13642 int32_t d_tri_edit_proc(int32_t msg,DIALOG *d,int32_t c)
13643 {
13644 jwin_button_proc(msg,d,c);
13645
13646 if(msg==MSG_CLICK)
13647 {
13648 int32_t v = getnumber("Piece Number",d->d1);
13649
13650 if(v>=0)
13651 {
13652 bound(v,1,8);
13653
13654 if(v!=d->d1)
13655 {
13656 DIALOG *tp = d - d->d2;
13657
13658 for(int32_t i=0; i<8; i++)
13659 {
13660 if(tp->d1==v)
13661 {
13662 tp->d1 = d->d1;
13663 ((char*)(tp->dp))[0] = d->d1+'0';
13664 jwin_button_proc(MSG_DRAW,tp,0);
13665 }
13666
13667 ++tp;
13668 }
13669
13670 d->d1 = v;
13671 ((char*)(d->dp))[0] = v+'0';
13672 }
13673 }
13674
13675 d->flags = 0;
13676 jwin_button_proc(MSG_DRAW,d,0);
13677 }
13678
13679 return D_O_K;
13680 }
13681
13682 static DIALOG tp_dlg[] =
13683 {
13684 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
13685 12 { jwin_win_proc, 56, 32, 208, 160, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Triforce Pieces", NULL, NULL },
13686 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
13687 12 { d_tri_frame_proc, 64, 56, 192, 96, jwin_pal[jcBOXFG], jwin_pal[jcBOX], 0, 0, 0, 0, NULL, NULL, NULL },
13688 // 3
13689 12 { d_tri_edit_proc, 138, 82, 17, 17, vc(14), vc(1), 0, 0, 0, 0, (void *) "1", NULL, NULL },
13690 12 { d_tri_edit_proc, 166, 82, 17, 17, vc(14), vc(1), 0, 0, 0, 1, (void *) "2", NULL, NULL },
13691 12 { d_tri_edit_proc, 90, 130, 17, 17, vc(14), vc(1), 0, 0, 0, 2, (void *) "3", NULL, NULL },
13692 12 { d_tri_edit_proc, 214, 130, 17, 17, vc(14), vc(1), 0, 0, 0, 3, (void *) "4", NULL, NULL },
13693 // 7
13694 12 { d_tri_edit_proc, 138, 110, 17, 17, vc(14), vc(1), 0, 0, 0, 4, (void *) "5", NULL, NULL },
13695 12 { d_tri_edit_proc, 118, 130, 17, 17, vc(14), vc(1), 0, 0, 0, 5, (void *) "6", NULL, NULL },
13696 12 { d_tri_edit_proc, 166, 110, 17, 17, vc(14), vc(1), 0, 0, 0, 6, (void *) "7", NULL, NULL },
13697 12 { d_tri_edit_proc, 186, 130, 17, 17, vc(14), vc(1), 0, 0, 0, 7, (void *) "8", NULL, NULL },
13698 // 11
13699 12 { jwin_button_proc, 90, 166, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
13700 12 { jwin_button_proc, 170, 166, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
13701 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
13702 };
13703
13704 int32_t onTriPieces()
13705 {
13706 tp_dlg[0].dp2=get_zc_font(font_lfont);
13707 char temptext[8][2];
13708
13709 for(int32_t i=0; i<8; i++)
13710 {
13711 tp_dlg[i+3].d1 = QMisc.triforce[i];
13712 // ((char*)(tp_dlg[i+3].dp))[0] = QMisc.triforce[i]+'0';
13713 sprintf(temptext[i], "%d", QMisc.triforce[i]);
13714 tp_dlg[i+3].dp=temptext[i];
13715 }
13716
13717 large_dialog(tp_dlg);
13718
13719 if(do_zqdialog(tp_dlg,-1) == 11)
13720 {
13721 saved=false;
13722
13723 for(int32_t i=0; i<8; i++)
13724 QMisc.triforce[i] = tp_dlg[i+3].d1;
13725 }
13726
13727 return D_O_K;
13728 }
13729
13730 int32_t d_maptile_proc(int32_t msg,DIALOG *d,int32_t c);
13731 bool small_dmap=false;
13732
13733 static DIALOG dmapmaps_dlg[] =
13734 {
13735
13736 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
13737 { jwin_win_proc, 4, 18, 313, 217, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Custom DMap Map Styles", NULL, NULL },
13738 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
13739 { jwin_button_proc, 93, 208, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
13740 { jwin_button_proc, 168, 208, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
13741 { d_ctext2_proc, 160, 38, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Minimaps", NULL, NULL },
13742 { d_ctext2_proc, 112, 46, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Without Map", NULL, NULL },
13743 { d_ctext2_proc, 208, 46, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "With Map", NULL, NULL },
13744
13745 { d_ctext2_proc, 162, 110, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Large Maps", NULL, NULL },
13746 { d_ctext2_proc, 80, 118, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Without Map", NULL, NULL },
13747 { d_ctext2_proc, 240, 118, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "With Map", NULL, NULL },
13748 // 5
13749 { d_maptile_proc, 72, 54, 80, 48, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
13750 { d_maptile_proc, 168, 54, 80, 48, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
13751 { d_maptile_proc, 8, 126, 144, 80, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
13752 { d_maptile_proc, 168, 126, 144, 80, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
13753 // 11
13754 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
13755 };
13756
13757 int32_t d_hexedit_proc(int32_t msg,DIALOG *d,int32_t c)
13758 {
13759 return jwin_hexedit_proc(msg,d,c);
13760 }
13761
13762 void drawgrid(BITMAP *dest,int32_t x,int32_t y,int32_t grid,int32_t fg,int32_t bg,int32_t div)
13763 {
13764 if(div!=-1)
13765 rectfill(dest,x-1,y-1,x+63,y+3,div);
13766
13767 for(int32_t dx=0; dx<64; dx+=8)
13768 {
13769 if(grid&0x80)
13770 rectfill(dest,x+dx,y,x+dx+6,y+2,fg);
13771 else if(bg!=-1)
13772 rectfill(dest,x+dx,y,x+dx+6,y+2,bg);
13773
13774 grid<<=1;
13775 }
13776 }
13777
13778 void drawovergrid(BITMAP *dest,int32_t x,int32_t y,int32_t grid,int32_t color,int32_t div)
13779 {
13780 if(div!=-1)
13781 rectfill(dest,x-1,y-1,x+63,y+3,div);
13782
13783 for(int32_t dx=0; dx<64; dx+=4)
13784 {
13785 rectfill(dest,x+dx,y,x+dx+2,y+2,color);
13786 grid<<=1;
13787 }
13788 }
13789
13790 void drawgrid(BITMAP *dest,int32_t x,int32_t y,int32_t w, int32_t h, int32_t tw, int32_t th, int32_t *grid,int32_t fg,int32_t bg,int32_t div)
13791 {
13792 //these are here to bypass compiler warnings about unused arguments
13793 w=w;
13794 tw=tw;
13795 th=th;
13796
13797 rectfill(dest,x,y,x+(8*8),y+(1*4),div);
13798
13799 for(int32_t dy=0; dy<h; dy++)
13800 {
13801 for(int32_t dx=0; dx<64; dx+=8)
13802 {
13803 if(grid[0]&0x80)
13804 rectfill(dest,x+dx,y,x+dx+6,y+2,fg);
13805 else
13806 rectfill(dest,x+dx,y,x+dx+6,y+2,bg);
13807
13808 grid[0]<<=1;
13809 }
13810 }
13811 }
13812
13813 void drawgrid_s(BITMAP *dest,int32_t x,int32_t y,int32_t grid,int32_t fg,int32_t bg,int32_t div)
13814 {
13815 rectfill(dest,x-1,y-1,x+63,y+3,div);
13816
13817 for(int32_t dx=0; dx<64; dx+=8)
13818 {
13819 rectfill(dest,x+dx,y,x+dx+6,y+2,bg);
13820
13821 if(grid&0x80)
13822 rectfill(dest,x+dx+2,y,x+dx+4,y+2,fg);
13823
13824 grid<<=1;
13825 }
13826 }
13827
13828 void drawdmap(int32_t dmap)
13829 {
13830 int32_t c;
13831 zcolors mc=QMisc.colors;
13832
13833 switch((DMaps[dmap].type&dmfTYPE))
13834 {
13835 case dmDNGN:
13836 case dmCAVE:
13837 clear_bitmap(dmapbmp_small);
13838
13839 if(DMaps[dmap].minimap_tile[1])
13840 ;
13841 // overworld_map_tile overrides the NES minimap. dungeon_map_tile does not.
13842 else for(int32_t y=1; y<33; y+=4)
13843 drawgrid(dmapbmp_small,0,y,DMaps[dmap].grid[y>>2], DMaps[dmap].flags&dmfMINIMAPCOLORFIX ? mc.cave_fg : mc.dngn_fg, -1, -1);
13844
13845 c=DMaps[dmap].compass;
13846 // rectfill(dmapbmp,(c&15)*8+3,(c>>4)*4+1,(c&15)*8+5,(c>>4)*4+3,dvc(2*4));
13847 rectfill(dmapbmp_small,(c&15)*8+3,(c>>4)*4+1,(c&15)*8+5,(c>>4)*4+3,vc(4));
13848 c=DMaps[dmap].cont;
13849 rectfill(dmapbmp_small,(c&15)*8+3,(c>>4)*4+1,(c&15)*8+5,(c>>4)*4+3,vc(10));
13850 break;
13851
13852 case dmOVERW:
13853 clear_bitmap(dmapbmp_small);
13854
13855 if(DMaps[dmap].minimap_tile[1])
13856 ;
13857 else if(!mc.overworld_map_tile)
13858 for(int32_t y=1; y<33; y+=4)
13859 drawovergrid(dmapbmp_small,1,y,DMaps[dmap].grid[y>>2],mc.overw_bg,vc(0));
13860
13861 c=DMaps[dmap].cont;
13862 rectfill(dmapbmp_small,(c&15)*4+1,(c>>4)*4+1,(c&15)*4+3,(c>>4)*4+3,vc(10));
13863 break;
13864
13865 case dmBSOVERW:
13866 clear_bitmap(dmapbmp_small);
13867
13868 if(DMaps[dmap].minimap_tile[1])
13869 ;
13870 else if(!mc.overworld_map_tile)
13871 for(int32_t y=1; y<33; y+=4)
13872 // drawgrid_s(dmapbmp,1,y,DMaps[dmap].grid[y>>2],dvc(2*4),dvc(2*3),dvc(3+4));
13873 drawgrid_s(dmapbmp_small,0,y,DMaps[dmap].grid[y>>2],mc.bs_goal,mc.bs_dk,vc(14));
13874
13875 c=DMaps[dmap].cont;
13876 rectfill(dmapbmp_small,(c&15)*8+3,(c>>4)*4+1,(c&15)*8+5,(c>>4)*4+3,vc(10));
13877 break;
13878 }
13879 }
13880
13881 void drawdmap_screen(int32_t x, int32_t y, int32_t w, int32_t h, int32_t dmap)
13882 {
13883 BITMAP *tempbmp = create_bitmap_ex(8,w,h);
13884 clear_to_color(tempbmp, vc(0));
13885 zcolors mc=QMisc.colors;
13886
13887 // rectfill(tempbmp,x,y,x+w-1,y+h-1,vc(0));
13888
13889 if(DMaps[dmap].minimap_tile[1])
13890 {
13891 draw_block(tempbmp,0,0,DMaps[dmap].minimap_tile[1],DMaps[dmap].minimap_cset[1],5,3);
13892 }
13893 else if(((DMaps[dmap].type&dmfTYPE)==dmDNGN || (DMaps[dmap].type&dmfTYPE)==dmCAVE) && mc.dungeon_map_tile)
13894 {
13895 draw_block(tempbmp,0,0,mc.dungeon_map_tile,mc.dungeon_map_cset,5,3);
13896 }
13897 else if(((DMaps[dmap].type&dmfTYPE)==dmOVERW || (DMaps[dmap].type&dmfTYPE)==dmBSOVERW) && mc.overworld_map_tile)
13898 {
13899 draw_block(tempbmp,0,0,mc.overworld_map_tile,mc.overworld_map_cset,5,3);
13900 }
13901
13902 masked_blit(dmapbmp_small,tempbmp,0,0,8,7,65,33);
13903
13904 blit(tempbmp,screen,0,0,x,y,w,h);
13905 destroy_bitmap(tempbmp);
13906
13907 }
13908
13909 int32_t d_dmaplist_proc(int32_t msg,DIALOG *d,int32_t c)
13910 {
13911 if(msg==MSG_DRAW)
13912 {
13913 int32_t dmap = d->d1;
13914 int32_t xy[6] = {44,92,128,100,128,110};
13915 //int32_t *xy = (int32_t*)(d->dp3);
13916 float temp_scale = 1.5;
13917
13918 drawdmap(dmap);
13919
13920 if(xy[0]>-1000&&xy[1]>-1000)
13921 {
13922 int32_t x = d->x+int32_t((xy[0]-2)*temp_scale);
13923 int32_t y = d->y+int32_t((xy[1]-2)*temp_scale);
13924 int32_t w = 84;
13925 int32_t h = 52;
13926 jwin_draw_frame(screen,x,y,w,h,FR_DEEP);
13927 drawdmap_screen(x+2,y+2,w-4,h-4,dmap);
13928 }
13929
13930 if(xy[2]>-1000&&xy[3]>-1000)
13931 {
13932 textprintf_ex(screen,get_zc_font(font_lfont_l),d->x+int32_t((xy[2])*temp_scale),d->y+int32_t((xy[3])*temp_scale),jwin_pal[jcBOXFG],jwin_pal[jcBOX],"Map: %-3d",DMaps[d->d1].map+1);
13933 }
13934
13935 if(xy[4]>-1000&&xy[5]>-1000)
13936 {
13937 textprintf_ex(screen,get_zc_font(font_lfont_l),d->x+int32_t((xy[4])*temp_scale),d->y+int32_t((xy[5])*temp_scale),jwin_pal[jcBOXFG],jwin_pal[jcBOX],"Level: %-3d",DMaps[d->d1].level);
13938 }
13939 }
13940
13941 return jwin_list_proc(msg,d,c);
13942 }
13943
13944 int32_t d_dropdmaplist_proc(int32_t msg,DIALOG *d,int32_t c)
13945 {
13946 if(msg==MSG_DRAW)
13947 {
13948 int32_t dmap = d->d1;
13949 int32_t *xy = (int32_t*)(d->dp3);
13950 float temp_scale = 1.5;
13951
13952 drawdmap(dmap);
13953
13954 if(xy[0]>-1000&&xy[1]>-1000)
13955 {
13956 int32_t x = d->x+int32_t((xy[0]-2)*temp_scale);
13957 int32_t y = d->y+int32_t((xy[1]-2)*temp_scale);
13958 int32_t w = 84;
13959 int32_t h = 52;
13960 jwin_draw_frame(screen,x,y,w,h,FR_DEEP);
13961 drawdmap_screen(x+2,y+2,w-4,h-4,dmap);
13962 }
13963
13964 if(xy[2]>-1000&&xy[3]>-1000)
13965 {
13966 textprintf_ex(screen,get_zc_font(font_lfont_l),d->x+int32_t((xy[2])*temp_scale),d->y+int32_t((xy[3])*temp_scale),jwin_pal[jcBOXFG],jwin_pal[jcBOX],"Map: %-3d",DMaps[d->d1].map+1);
13967 }
13968
13969 if(xy[4]>-1000&&xy[5]>-1000)
13970 {
13971 textprintf_ex(screen,get_zc_font(font_lfont_l),d->x+int32_t((xy[4])*temp_scale),d->y+int32_t((xy[5])*temp_scale),jwin_pal[jcBOXFG],jwin_pal[jcBOX],"Level: %-3d",DMaps[d->d1].level);
13972 }
13973 }
13974
13975 return jwin_droplist_proc(msg,d,c);
13976 }
13977
13978 void drawxmap(ALLEGRO_BITMAP* dest, int32_t themap, int32_t xoff, bool large, int dx, int dy)
13979 {
13980 ALLEGRO_STATE old_state;
13981 al_store_state(&old_state, ALLEGRO_STATE_TARGET_BITMAP);
13982
13983 al_set_target_bitmap(dest);
13984 al_clear_to_color(al_map_rgba(0, 0, 0, 0));
13985
13986 int32_t cols = (large ? 8 : 16);
13987 int32_t col_width = large ? 22 : 11;
13988 int32_t dot_width = (large ? 6 : 4);
13989 int32_t dot_offset = (large ? 7 : 3);
13990 int32_t l = 10;
13991
13992 for (int32_t y = 0; y < 8; y++)
13993 {
13994 // Users might have set the dmap to a map that has since been deleted.
13995 if (themap >= Map.getMapCount())
13996 break;
13997
13998 for (int32_t x = 0; x < cols; x++)
13999 {
14000 if (x + xoff < 0 || x + xoff > 15)
14001 continue;
14002
14003 const mapscr* scr = get_canonical_scr(themap, y * 16 + x + (large ? xoff : 0));
14004 if (!(scr->valid & mVALID))
14005 continue;
14006
14007 al_draw_filled_rectangle(dx + (x * col_width), dy + (y * l), dx + (x * col_width + col_width), dy + ((y * l) + l), real_lc1(scr->color));
14008 al_draw_filled_rectangle(dx + (x * col_width + dot_offset), dy + (y * l + 3), dx + (x * col_width + dot_offset + dot_width), dy + (y * l + l - 3), real_lc2(scr->color));
14009 }
14010 }
14011
14012 al_restore_state(&old_state);
14013 }
14014
14015 const char *dmapscriptdroplist(int32_t index, int32_t *list_size)
14016 {
14017 if(index<0)
14018 {
14019 *list_size = bidmaps_cnt;
14020 return NULL;
14021 }
14022
14023 return bidmaps[index].first.c_str();
14024 }
14025
14026 12 static ListData dmapscript_list(dmapscriptdroplist, &a4fonts[font_pfont]);
14027
14028 //int32_t selectdmapxy[6] = {90,142,164,150,164,160};
14029 int32_t selectdmapxy[6] = {44,92,128,100,128,110};
14030
14031 12 static ListData dmap_list(dmaplist, &font);
14032
14033 12 static dmap copiedDMap;
14034 static byte dmapcopied = 0;
14035
14036 int32_t writesomedmaps(PACKFILE *f, int32_t first, int32_t last, int32_t max)
14037 {
14038
14039 dword section_version=V_DMAPS;
14040 int32_t zversion = ZELDA_VERSION;
14041 int32_t zbuild = VERSION_BUILD;
14042
14043 if(!p_iputl(V_ZDMAP,f))
14044 {
14045 return 0;
14046 }
14047
14048 //section version info
14049 if(!p_iputl(zversion,f))
14050 {
14051 return 0;
14052 }
14053 if(!p_iputl(zbuild,f))
14054 {
14055 return 0;
14056 }
14057 if(!p_iputw(section_version,f))
14058 {
14059 new_return(2);
14060 }
14061
14062 if(!write_deprecated_section_cversion(section_version, f))
14063 {
14064 new_return(3);
14065 }
14066 //max possible at this time
14067 if(!p_iputl(max,f))
14068 {
14069 new_return(4);
14070 }
14071 //first id written
14072 if(!p_iputl(first,f))
14073 {
14074 new_return(5);
14075 }
14076 //last id written
14077 if(!p_iputl(last,f))
14078 {
14079 new_return(6);
14080 }
14081 int32_t count = last-first;
14082 //number written
14083 if(!p_iputl(count,f))
14084 {
14085 new_return(7);
14086 }
14087
14088
14089 for ( int32_t i = first; i <= last; ++i )
14090 {
14091 if ( i > max ) break;
14092
14093 if(!p_putc(DMaps[i].map,f))
14094 {
14095 new_return(8);
14096 }
14097
14098 if(!p_iputw(DMaps[i].level,f))
14099 {
14100 new_return(9);
14101 }
14102
14103 if(!p_putc(DMaps[i].xoff,f))
14104 {
14105 new_return(10);
14106 }
14107
14108 if(!p_putc(DMaps[i].compass,f))
14109 {
14110 new_return(11);
14111 }
14112
14113 if(!p_iputw(DMaps[i].color,f))
14114 {
14115 new_return(12);
14116 }
14117
14118 if(!p_putc(DMaps[i].midi,f))
14119 {
14120 new_return(13);
14121 }
14122
14123 if(!p_putc(DMaps[i].cont,f))
14124 {
14125 new_return(14);
14126 }
14127
14128 if(!p_putc(DMaps[i].type,f))
14129 {
14130 new_return(15);
14131 }
14132
14133 for(int32_t j=0; j<8; j++)
14134 {
14135 if(!p_putc(DMaps[i].grid[j],f))
14136 {
14137 new_return(16);
14138 }
14139 }
14140
14141 //16
14142 if(!pfwrite(&DMaps[i].name,sizeof(DMaps[0].name),f))
14143 {
14144 new_return(17);
14145 }
14146
14147 if(!p_putwstr(DMaps[i].title,f))
14148 {
14149 new_return(18);
14150 }
14151
14152 if(!pfwrite(&DMaps[i].intro,sizeof(DMaps[0].intro),f))
14153 {
14154 new_return(19);
14155 }
14156
14157 if(!p_iputl(DMaps[i].minimap_tile[0],f))
14158 {
14159 new_return(20);
14160 }
14161
14162 if(!p_putc(DMaps[i].minimap_cset[0],f))
14163 {
14164 new_return(21);
14165 }
14166
14167 if(!p_iputl(DMaps[i].minimap_tile[1],f))
14168 {
14169 new_return(22);
14170 }
14171
14172 if(!p_putc(DMaps[i].minimap_cset[1],f))
14173 {
14174 new_return(23);
14175 }
14176
14177 if(!p_iputl(DMaps[i].largemap_tile[0],f))
14178 {
14179 new_return(24);
14180 }
14181
14182 if(!p_putc(DMaps[i].largemap_cset[0],f))
14183 {
14184 new_return(25);
14185 }
14186
14187 if(!p_iputl(DMaps[i].largemap_tile[1],f))
14188 {
14189 new_return(26);
14190 }
14191
14192 if(!p_putc(DMaps[i].largemap_cset[1],f))
14193 {
14194 new_return(27);
14195 }
14196
14197 if(!pfwrite(&DMaps[i].tmusic,sizeof(DMaps[0].tmusic),f))
14198 {
14199 new_return(28);
14200 }
14201
14202 if(!p_putc(DMaps[i].tmusictrack,f))
14203 {
14204 new_return(29);
14205 }
14206
14207 if(!p_putc(DMaps[i].active_subscreen,f))
14208 {
14209 new_return(30);
14210 }
14211
14212 if(!p_putc(DMaps[i].passive_subscreen,f))
14213 {
14214 new_return(31);
14215 }
14216
14217 byte disabled[32];
14218 memset(disabled,0,32);
14219
14220 for(int32_t j=0; j<MAXITEMS; j++)
14221 {
14222 if(DMaps[i].disableditems[j])
14223 {
14224 disabled[j/8] |= (1 << (j%8));
14225 }
14226 }
14227
14228 if(!pfwrite(disabled,32,f))
14229 {
14230 new_return(32);
14231 }
14232
14233 if(!p_iputl(DMaps[i].flags,f))
14234 {
14235 new_return(33);
14236 }
14237 if(!p_putc(DMaps[i].sideview,f))
14238 {
14239 new_return(30);
14240 }
14241 if(!p_iputw(DMaps[i].script,f))
14242 {
14243 new_return(31);
14244 }
14245 for ( int32_t q = 0; q < 8; q++ )
14246 {
14247 if(!p_iputl(DMaps[i].initD[q],f))
14248 {
14249 new_return(32);
14250 }
14251
14252 }
14253 for ( int32_t q = 0; q < 8; q++ )
14254 {
14255 for ( int32_t w = 0; w < 65; w++ )
14256 {
14257 if (!p_putc(DMaps[i].initD_label[q][w],f))
14258 {
14259 new_return(33);
14260 }
14261 }
14262 }
14263 if(!p_iputw(DMaps[i].active_sub_script,f))
14264 {
14265 new_return(34);
14266 }
14267 if(!p_iputw(DMaps[i].passive_sub_script,f))
14268 {
14269 new_return(35);
14270 }
14271 for(int32_t q = 0; q < 8; ++q)
14272 {
14273 if(!p_iputl(DMaps[i].sub_initD[q],f))
14274 {
14275 new_return(36);
14276 }
14277 }
14278 for(int32_t q = 0; q < 8; ++q)
14279 {
14280 for(int32_t w = 0; w < 65; ++w)
14281 {
14282 if(!p_putc(DMaps[i].sub_initD_label[q][w],f))
14283 {
14284 new_return(37);
14285 }
14286 }
14287 }
14288 if(!p_iputw(DMaps[i].onmap_script,f))
14289 {
14290 new_return(35);
14291 }
14292 for(int32_t q = 0; q < 8; ++q)
14293 {
14294 if(!p_iputl(DMaps[i].onmap_initD[q],f))
14295 {
14296 new_return(36);
14297 }
14298 }
14299 for(int32_t q = 0; q < 8; ++q)
14300 {
14301 for(int32_t w = 0; w < 65; ++w)
14302 {
14303 if(!p_putc(DMaps[i].onmap_initD_label[q][w],f))
14304 {
14305 new_return(37);
14306 }
14307 }
14308 }
14309 if (!p_iputw(DMaps[i].mirrorDMap, f))
14310 {
14311 new_return(38);
14312 }
14313 if (!p_iputl(DMaps[i].tmusic_loop_start, f))
14314 {
14315 new_return(39);
14316 }
14317 if (!p_iputl(DMaps[i].tmusic_loop_end, f))
14318 {
14319 new_return(40);
14320 }
14321 if (!p_iputl(DMaps[i].tmusic_xfade_in, f))
14322 {
14323 new_return(41);
14324 }
14325 if (!p_iputl(DMaps[i].tmusic_xfade_out, f))
14326 {
14327 new_return(42);
14328 }
14329 }
14330
14331 return 1;
14332 }
14333
14334
14335 int32_t readsomedmaps(PACKFILE *f)
14336 {
14337 dword section_version = 0;
14338 int32_t zversion = 0;
14339 int32_t zbuild = 0;
14340 dmap tempdmap{};
14341
14342 int32_t first = 0, last = 0, max = 0, count = 0;
14343 int32_t datatype_version = 0;
14344
14345 //char dmapstring[64]={0};
14346 //section version info
14347 if(!p_igetl(&datatype_version,f))
14348 {
14349 return 0;
14350 }
14351 if ( datatype_version < 0 )
14352 {
14353 if(!p_igetl(&zversion,f))
14354 {
14355 return 0;
14356 }
14357 }
14358 else
14359 {
14360 zversion = datatype_version;
14361 }
14362 if(!p_igetl(&zbuild,f))
14363 {
14364 return 0;
14365 }
14366
14367 if(!p_igetw(&section_version,f))
14368 {
14369 return 0;
14370 }
14371
14372 if(!read_deprecated_section_cversion(f))
14373 {
14374 return 0;
14375 }
14376 if ( datatype_version < 0 )
14377 {
14378 if(!p_igetl(&max,f))
14379 {
14380 return 0;
14381 }
14382 if(!p_igetl(&first,f))
14383 {
14384 return 0;
14385 }
14386 if(!p_igetl(&last,f))
14387 {
14388 return 0;
14389 }
14390 if(!p_igetl(&count,f))
14391 {
14392 return 0;
14393 }
14394 }
14395 else
14396 {
14397 first = 0;
14398 last = 0;
14399 count = 1;
14400 max = 255;
14401 }
14402
14403
14404
14405
14406 al_trace("readsomedmaps section_version: %d\n", section_version);
14407
14408 if ( zversion > ZELDA_VERSION )
14409 {
14410 al_trace("Cannot read .zdmap packfile made in ZC version (%x) in this version of ZC (%x)\n", zversion, ZELDA_VERSION);
14411 return 0;
14412 }
14413 else if (( section_version > V_DMAPS ))
14414 {
14415 al_trace("Cannot read .zdmap packfile made using V_DMAPS (%d)\n", section_version);
14416 return 0;
14417 }
14418 else
14419 {
14420 al_trace("Reading a .zdmap packfile made in ZC Version: %x, Build: %d\n", zversion, zbuild);
14421 }
14422 //if(!pfread(&dmapstring, 64, f))
14423 //{
14424 // return 0;
14425 //}
14426
14427
14428
14429 for ( int32_t i = first; i <= last; ++i )
14430 {
14431 if(!p_getc(&tempdmap.map,f))
14432 {
14433 return 0;
14434 }
14435
14436 if(!p_igetw(&tempdmap.level,f))
14437 {
14438 return 0;
14439 }
14440
14441 if(!p_getc(&tempdmap.xoff,f))
14442 {
14443 return 0;
14444 }
14445
14446 if(!p_getc(&tempdmap.compass,f))
14447 {
14448 return 0;
14449 }
14450
14451 if(!p_igetw(&tempdmap.color,f))
14452 {
14453 return 0;
14454 }
14455
14456 if(!p_getc(&tempdmap.midi,f))
14457 {
14458 return 0;
14459 }
14460
14461 if(!p_getc(&tempdmap.cont,f))
14462 {
14463 return 0;
14464 }
14465
14466 if(!p_getc(&tempdmap.type,f))
14467 {
14468 return 0;
14469 }
14470
14471 for(int32_t j=0; j<8; j++)
14472 {
14473 if(!p_getc(&tempdmap.grid[j],f))
14474 {
14475 return 0;
14476 }
14477 }
14478
14479 //16
14480 if(!pfread(&tempdmap.name,sizeof(DMaps[0].name),f))
14481 {
14482 return 0;
14483 }
14484
14485 if (section_version<20)
14486 {
14487 char title[22];
14488 if (!p_getstr(title, sizeof(title) - 1, f))
14489 {
14490 return 0;
14491 }
14492 tempdmap.title.assign(title);
14493 }
14494 else
14495 {
14496 if (!p_getwstr(&tempdmap.title, f))
14497 {
14498 return 0;
14499 }
14500 }
14501
14502 if(!pfread(&tempdmap.intro,sizeof(DMaps[0].intro),f))
14503 {
14504 return 0;
14505 }
14506
14507 if(!p_igetl(&tempdmap.minimap_tile[0],f))
14508 {
14509 return 0;
14510 }
14511
14512 if(!p_getc(&tempdmap.minimap_cset[0],f))
14513 {
14514 return 0;
14515 }
14516
14517 if(!p_igetl(&tempdmap.minimap_tile[1],f))
14518 {
14519 return 0;
14520 }
14521
14522 if(!p_getc(&tempdmap.minimap_cset[1],f))
14523 {
14524 return 0;
14525 }
14526
14527 if(!p_igetl(&tempdmap.largemap_tile[0],f))
14528 {
14529 return 0;
14530 }
14531
14532 if(!p_getc(&tempdmap.largemap_cset[0],f))
14533 {
14534 return 0;
14535 }
14536
14537 if(!p_igetl(&tempdmap.largemap_tile[1],f))
14538 {
14539 return 0;
14540 }
14541
14542 if(!p_getc(&tempdmap.largemap_cset[1],f))
14543 {
14544 return 0;
14545 }
14546
14547 if(!pfread(&tempdmap.tmusic,sizeof(DMaps[0].tmusic),f))
14548 {
14549 return 0;
14550 }
14551
14552 if(!p_getc(&tempdmap.tmusictrack,f))
14553 {
14554 return 0;
14555 }
14556
14557 if(!p_getc(&tempdmap.active_subscreen,f))
14558 {
14559 return 0;
14560 }
14561
14562 if(!p_getc(&tempdmap.passive_subscreen,f))
14563 {
14564 return 0;
14565 }
14566
14567 byte disabled[32];
14568 memset(disabled,0,32);
14569
14570 if(!pfread(&disabled, 32, f)) return 0;
14571
14572 for(int32_t j=0; j<MAXITEMS; j++)
14573 {
14574 if(disabled[j/8] & (1 << (j%8))) tempdmap.disableditems[j]=1;
14575 else tempdmap.disableditems[j]=0;
14576 }
14577
14578
14579 if(!p_igetl(&tempdmap.flags,f))
14580 {
14581 return 0;
14582 }
14583 if ( zversion >= 0x255 )
14584 {
14585 if ( section_version >= 14 )
14586 {
14587 //2.55 starts here
14588 if(!p_getc(&tempdmap.sideview,f))
14589 {
14590 return 0;
14591 }
14592 if(!p_igetw(&tempdmap.script,f))
14593 {
14594 return 0;
14595 }
14596 for ( int32_t q = 0; q < 8; q++ )
14597 {
14598 if(!p_igetl(&tempdmap.initD[q],f))
14599 {
14600 return 0;
14601 }
14602
14603 }
14604 for ( int32_t q = 0; q < 8; q++ )
14605 {
14606 for ( int32_t w = 0; w < 65; w++ )
14607 {
14608 if (!p_getc(&tempdmap.initD_label[q][w],f))
14609 {
14610 return 0;
14611 }
14612 }
14613 }
14614 if(!p_igetw(&tempdmap.active_sub_script,f))
14615 {
14616 return 0;
14617 }
14618 if(!p_igetw(&tempdmap.passive_sub_script,f))
14619 {
14620 return 0;
14621 }
14622 for(int32_t q = 0; q < 8; ++q)
14623 {
14624 if(!p_igetl(&tempdmap.sub_initD[q],f))
14625 {
14626 return 0;
14627 }
14628 }
14629 for(int32_t q = 0; q < 8; ++q)
14630 {
14631 for(int32_t w = 0; w < 65; ++w)
14632 {
14633 if(!p_getc(&tempdmap.sub_initD_label[q][w],f))
14634 {
14635 return 0;
14636 }
14637 }
14638 }
14639 if(!p_igetw(&tempdmap.onmap_script,f))
14640 {
14641 return 0;
14642 }
14643 for(int32_t q = 0; q < 8; ++q)
14644 {
14645 if(!p_igetl(&tempdmap.onmap_initD[q],f))
14646 {
14647 return 0;
14648 }
14649 }
14650 for(int32_t q = 0; q < 8; ++q)
14651 {
14652 for(int32_t w = 0; w < 65; ++w)
14653 {
14654 if(!p_getc(&tempdmap.onmap_initD_label[q][w],f))
14655 {
14656 return 0;
14657 }
14658 }
14659 }
14660 if (!p_igetw(&tempdmap.mirrorDMap, f))
14661 {
14662 return 0;
14663 }
14664 if (!p_igetl(&tempdmap.tmusic_loop_start, f))
14665 {
14666 return 0;
14667 }
14668 if (!p_igetl(&tempdmap.tmusic_loop_end, f))
14669 {
14670 return 0;
14671 }
14672 if (!p_igetl(&tempdmap.tmusic_xfade_in, f))
14673 {
14674 return 0;
14675 }
14676 if (!p_igetl(&tempdmap.tmusic_xfade_out, f))
14677 {
14678 return 0;
14679 }
14680 }
14681 }
14682 DMaps[i].clear();
14683 DMaps[i] = tempdmap;
14684 }
14685
14686 return 1;
14687 }
14688
14689
14690
14691 int32_t writeonedmap(PACKFILE *f, int32_t i)
14692 {
14693
14694 dword section_version=V_DMAPS;
14695 int32_t zversion = ZELDA_VERSION;
14696 int32_t zbuild = VERSION_BUILD;
14697
14698
14699 //section version info
14700 if(!p_iputl(V_ZDMAP,f))
14701 {
14702 return 0;
14703 }
14704 if(!p_iputl(zversion,f))
14705 {
14706 return 0;
14707 }
14708 if(!p_iputl(zbuild,f))
14709 {
14710 return 0;
14711 }
14712 if(!p_iputw(section_version,f))
14713 {
14714 new_return(2);
14715 }
14716
14717 if(!write_deprecated_section_cversion(section_version, f))
14718 {
14719 new_return(3);
14720 }
14721
14722
14723
14724 if(!p_putc(DMaps[i].map,f))
14725 {
14726 new_return(6);
14727 }
14728
14729 if(!p_iputw(DMaps[i].level,f))
14730 {
14731 new_return(7);
14732 }
14733
14734 if(!p_putc(DMaps[i].xoff,f))
14735 {
14736 new_return(8);
14737 }
14738
14739 if(!p_putc(DMaps[i].compass,f))
14740 {
14741 new_return(9);
14742 }
14743
14744 if(!p_iputw(DMaps[i].color,f))
14745 {
14746 new_return(10);
14747 }
14748
14749 if(!p_putc(DMaps[i].midi,f))
14750 {
14751 new_return(11);
14752 }
14753
14754 if(!p_putc(DMaps[i].cont,f))
14755 {
14756 new_return(12);
14757 }
14758
14759 if(!p_putc(DMaps[i].type,f))
14760 {
14761 new_return(13);
14762 }
14763
14764 for(int32_t j=0; j<8; j++)
14765 {
14766 if(!p_putc(DMaps[i].grid[j],f))
14767 {
14768 new_return(14);
14769 }
14770 }
14771
14772 //16
14773 if(!pfwrite(&DMaps[i].name,sizeof(DMaps[0].name),f))
14774 {
14775 new_return(15);
14776 }
14777
14778 if(!pfwrite(&DMaps[i].title,sizeof(DMaps[0].title),f))
14779 {
14780 new_return(16);
14781 }
14782
14783 if(!pfwrite(&DMaps[i].intro,sizeof(DMaps[0].intro),f))
14784 {
14785 new_return(17);
14786 }
14787
14788 if(!p_iputl(DMaps[i].minimap_tile[0],f))
14789 {
14790 new_return(18);
14791 }
14792
14793 if(!p_putc(DMaps[i].minimap_cset[0],f))
14794 {
14795 new_return(19);
14796 }
14797
14798 if(!p_iputl(DMaps[i].minimap_tile[1],f))
14799 {
14800 new_return(20);
14801 }
14802
14803 if(!p_putc(DMaps[i].minimap_cset[1],f))
14804 {
14805 new_return(21);
14806 }
14807
14808 if(!p_iputl(DMaps[i].largemap_tile[0],f))
14809 {
14810 new_return(22);
14811 }
14812
14813 if(!p_putc(DMaps[i].largemap_cset[0],f))
14814 {
14815 new_return(23);
14816 }
14817
14818 if(!p_iputl(DMaps[i].largemap_tile[1],f))
14819 {
14820 new_return(24);
14821 }
14822
14823 if(!p_putc(DMaps[i].largemap_cset[1],f))
14824 {
14825 new_return(25);
14826 }
14827
14828 if(!pfwrite(&DMaps[i].tmusic,sizeof(DMaps[0].tmusic),f))
14829 {
14830 new_return(26);
14831 }
14832
14833 if(!p_putc(DMaps[i].tmusictrack,f))
14834 {
14835 new_return(25);
14836 }
14837
14838 if(!p_putc(DMaps[i].active_subscreen,f))
14839 {
14840 new_return(26);
14841 }
14842
14843 if(!p_putc(DMaps[i].passive_subscreen,f))
14844 {
14845 new_return(27);
14846 }
14847
14848 byte disabled[32];
14849 memset(disabled,0,32);
14850
14851 for(int32_t j=0; j<MAXITEMS; j++)
14852 {
14853 if(DMaps[i].disableditems[j])
14854 {
14855 disabled[j/8] |= (1 << (j%8));
14856 }
14857 }
14858
14859 if(!pfwrite(disabled,32,f))
14860 {
14861 new_return(28);
14862 }
14863
14864 if(!p_iputl(DMaps[i].flags,f))
14865 {
14866 new_return(29);
14867 }
14868 if(!p_putc(DMaps[i].sideview,f))
14869 {
14870 new_return(30);
14871 }
14872 if(!p_iputw(DMaps[i].script,f))
14873 {
14874 new_return(31);
14875 }
14876 for ( int32_t q = 0; q < 8; q++ )
14877 {
14878 if(!p_iputl(DMaps[i].initD[q],f))
14879 {
14880 new_return(32);
14881 }
14882
14883 }
14884 for ( int32_t q = 0; q < 8; q++ )
14885 {
14886 for ( int32_t w = 0; w < 65; w++ )
14887 {
14888 if (!p_putc(DMaps[i].initD_label[q][w],f))
14889 {
14890 new_return(33);
14891 }
14892 }
14893 }
14894 if(!p_iputw(DMaps[i].active_sub_script,f))
14895 {
14896 new_return(34);
14897 }
14898 if(!p_iputw(DMaps[i].passive_sub_script,f))
14899 {
14900 new_return(35);
14901 }
14902 for(int32_t q = 0; q < 8; ++q)
14903 {
14904 if(!p_iputl(DMaps[i].sub_initD[q],f))
14905 {
14906 new_return(36);
14907 }
14908 }
14909 for(int32_t q = 0; q < 8; ++q)
14910 {
14911 for(int32_t w = 0; w < 65; ++w)
14912 {
14913 if(!p_putc(DMaps[i].sub_initD_label[q][w],f))
14914 {
14915 new_return(37);
14916 }
14917 }
14918 }
14919 if(!p_iputw(DMaps[i].onmap_script,f))
14920 {
14921 new_return(35);
14922 }
14923 for(int32_t q = 0; q < 8; ++q)
14924 {
14925 if(!p_iputl(DMaps[i].onmap_initD[q],f))
14926 {
14927 new_return(36);
14928 }
14929 }
14930 for(int32_t q = 0; q < 8; ++q)
14931 {
14932 for(int32_t w = 0; w < 65; ++w)
14933 {
14934 if(!p_putc(DMaps[i].onmap_initD_label[q][w],f))
14935 {
14936 new_return(37);
14937 }
14938 }
14939 }
14940 if (!p_iputw(DMaps[i].mirrorDMap, f))
14941 {
14942 new_return(38);
14943 }
14944 if (!p_iputl(DMaps[i].tmusic_loop_start, f))
14945 {
14946 new_return(39);
14947 }
14948 if (!p_iputl(DMaps[i].tmusic_loop_end, f))
14949 {
14950 new_return(40);
14951 }
14952 if (!p_iputl(DMaps[i].tmusic_xfade_in, f))
14953 {
14954 new_return(41);
14955 }
14956 if (!p_iputl(DMaps[i].tmusic_xfade_out, f))
14957 {
14958 new_return(42);
14959 }
14960
14961 return 1;
14962 }
14963
14964
14965 int32_t readonedmap(PACKFILE *f, int32_t index)
14966 {
14967 dword section_version = 0;
14968 int32_t zversion = 0;
14969 int32_t zbuild = 0;
14970 dmap tempdmap{};
14971 int32_t datatype_version = 0;
14972 int32_t first = 0;
14973 int32_t last = 0;
14974 int32_t max = 0;
14975 int32_t count = 0;
14976
14977 //char dmapstring[64]={0};
14978 //section version info
14979 if(!p_igetl(&datatype_version,f))
14980 {
14981 return 0;
14982 }
14983 if ( datatype_version < 0 )
14984 {
14985 if(!p_igetl(&zversion,f))
14986 {
14987 return 0;
14988 }
14989 }
14990 else
14991 {
14992 zversion = datatype_version;
14993 }
14994 if(!p_igetl(&zbuild,f))
14995 {
14996 return 0;
14997 }
14998
14999 if(!p_igetw(&section_version,f))
15000 {
15001 return 0;
15002 }
15003
15004 if(!read_deprecated_section_cversion(f))
15005 {
15006 return 0;
15007 }
15008 al_trace("readonedmap section_version: %d\n", section_version);
15009
15010
15011 if ( datatype_version < 0 )
15012 {
15013 if(!p_igetl(&max,f))
15014 {
15015 return 0;
15016 }
15017 if(!p_igetl(&first,f))
15018 {
15019 return 0;
15020 }
15021 if(!p_igetl(&last,f))
15022 {
15023 return 0;
15024 }
15025 if(!p_igetl(&count,f))
15026 {
15027 return 0;
15028 }
15029 }
15030 if ( zversion > ZELDA_VERSION )
15031 {
15032 al_trace("Cannot read .zdmap packfile made in ZC version (%x) in this version of ZC (%x)\n", zversion, ZELDA_VERSION);
15033 return 0;
15034 }
15035 else if (( section_version > V_DMAPS ))
15036 {
15037 al_trace("Cannot read .zdmap packfile made using V_DMAPS (%d)\n", section_version);
15038 return 0;
15039 }
15040 else
15041 {
15042 al_trace("Reading a .zdmap packfile made in ZC Version: %x, Build: %d\n", zversion, zbuild);
15043 }
15044 //if(!pfread(&dmapstring, 64, f))
15045 //{
15046 // return 0;
15047 //}
15048
15049
15050
15051
15052 if(!p_getc(&tempdmap.map,f))
15053 {
15054 return 0;
15055 }
15056
15057 if(!p_igetw(&tempdmap.level,f))
15058 {
15059 return 0;
15060 }
15061
15062 if(!p_getc(&tempdmap.xoff,f))
15063 {
15064 return 0;
15065 }
15066
15067 if(!p_getc(&tempdmap.compass,f))
15068 {
15069 return 0;
15070 }
15071
15072 if(!p_igetw(&tempdmap.color,f))
15073 {
15074 return 0;
15075 }
15076
15077 if(!p_getc(&tempdmap.midi,f))
15078 {
15079 return 0;
15080 }
15081
15082 if(!p_getc(&tempdmap.cont,f))
15083 {
15084 return 0;
15085 }
15086
15087 if(!p_getc(&tempdmap.type,f))
15088 {
15089 return 0;
15090 }
15091
15092 for(int32_t j=0; j<8; j++)
15093 {
15094 if(!p_getc(&tempdmap.grid[j],f))
15095 {
15096 return 0;
15097 }
15098 }
15099
15100 //16
15101 if(!pfread(&tempdmap.name,sizeof(DMaps[0].name),f))
15102 {
15103 return 0;
15104 }
15105
15106 if (section_version<20)
15107 {
15108 char title[22];
15109 if (!p_getstr(title, sizeof(title) - 1, f))
15110 {
15111 return 0;
15112 }
15113 tempdmap.title.assign(title);
15114 }
15115 else
15116 {
15117 if (!p_getwstr(&tempdmap.title, f))
15118 {
15119 return 0;
15120 }
15121 }
15122
15123 if(!pfread(&tempdmap.title,sizeof(DMaps[0].title),f))
15124 {
15125 return 0;
15126 }
15127
15128 if(!pfread(&tempdmap.intro,sizeof(DMaps[0].intro),f))
15129 {
15130 return 0;
15131 }
15132
15133 if(!p_igetl(&tempdmap.minimap_tile[0],f))
15134 {
15135 return 0;
15136 }
15137
15138 if(!p_getc(&tempdmap.minimap_cset[0],f))
15139 {
15140 return 0;
15141 }
15142
15143 if(!p_igetl(&tempdmap.minimap_tile[1],f))
15144 {
15145 return 0;
15146 }
15147
15148 if(!p_getc(&tempdmap.minimap_cset[1],f))
15149 {
15150 return 0;
15151 }
15152
15153 if(!p_igetl(&tempdmap.largemap_tile[0],f))
15154 {
15155 return 0;
15156 }
15157
15158 if(!p_getc(&tempdmap.largemap_cset[0],f))
15159 {
15160 return 0;
15161 }
15162
15163 if(!p_igetl(&tempdmap.largemap_tile[1],f))
15164 {
15165 return 0;
15166 }
15167
15168 if(!p_getc(&tempdmap.largemap_cset[1],f))
15169 {
15170 return 0;
15171 }
15172
15173 if(!pfread(&tempdmap.tmusic,sizeof(DMaps[0].tmusic),f))
15174 {
15175 return 0;
15176 }
15177
15178 if(!p_getc(&tempdmap.tmusictrack,f))
15179 {
15180 return 0;
15181 }
15182
15183 if(!p_getc(&tempdmap.active_subscreen,f))
15184 {
15185 return 0;
15186 }
15187
15188 if(!p_getc(&tempdmap.passive_subscreen,f))
15189 {
15190 return 0;
15191 }
15192
15193 byte disabled[32];
15194 memset(disabled,0,32);
15195
15196 if(!pfread(&disabled, 32, f)) return 0;
15197
15198 for(int32_t j=0; j<MAXITEMS; j++)
15199 {
15200 if(disabled[j/8] & (1 << (j%8))) tempdmap.disableditems[j]=1;
15201 else tempdmap.disableditems[j]=0;
15202 }
15203
15204
15205 if(!p_igetl(&tempdmap.flags,f))
15206 {
15207 return 0;
15208 }
15209 if ( zversion >= 0x255 )
15210 {
15211 if ( section_version >= 14 )
15212 {
15213 //2.55 starts here
15214 if(!p_getc(&tempdmap.sideview,f))
15215 {
15216 return 0;
15217 }
15218 if(!p_igetw(&tempdmap.script,f))
15219 {
15220 return 0;
15221 }
15222 for ( int32_t q = 0; q < 8; q++ )
15223 {
15224 if(!p_igetl(&tempdmap.initD[q],f))
15225 {
15226 return 0;
15227 }
15228
15229 }
15230 for ( int32_t q = 0; q < 8; q++ )
15231 {
15232 for ( int32_t w = 0; w < 65; w++ )
15233 {
15234 if (!p_getc(&tempdmap.initD_label[q][w],f))
15235 {
15236 return 0;
15237 }
15238 }
15239 }
15240 if(!p_igetw(&tempdmap.active_sub_script,f))
15241 {
15242 return 0;
15243 }
15244 if(!p_igetw(&tempdmap.passive_sub_script,f))
15245 {
15246 return 0;
15247 }
15248 for(int32_t q = 0; q < 8; ++q)
15249 {
15250 if(!p_igetl(&tempdmap.sub_initD[q],f))
15251 {
15252 return 0;
15253 }
15254 }
15255 for(int32_t q = 0; q < 8; ++q)
15256 {
15257 for(int32_t w = 0; w < 65; ++w)
15258 {
15259 if(!p_getc(&tempdmap.sub_initD_label[q][w],f))
15260 {
15261 return 0;
15262 }
15263 }
15264 }
15265 if(!p_igetw(&tempdmap.onmap_script,f))
15266 {
15267 return 0;
15268 }
15269 for(int32_t q = 0; q < 8; ++q)
15270 {
15271 if(!p_igetl(&tempdmap.onmap_initD[q],f))
15272 {
15273 return 0;
15274 }
15275 }
15276 for(int32_t q = 0; q < 8; ++q)
15277 {
15278 for(int32_t w = 0; w < 65; ++w)
15279 {
15280 if(!p_getc(&tempdmap.onmap_initD_label[q][w],f))
15281 {
15282 return 0;
15283 }
15284 }
15285 }
15286 if (!p_igetw(&tempdmap.mirrorDMap, f))
15287 {
15288 return 0;
15289 }
15290 if (!p_igetl(&tempdmap.tmusic_loop_start, f))
15291 {
15292 return 0;
15293 }
15294 if (!p_igetl(&tempdmap.tmusic_loop_end, f))
15295 {
15296 return 0;
15297 }
15298 if (!p_igetl(&tempdmap.tmusic_xfade_in, f))
15299 {
15300 return 0;
15301 }
15302 if (!p_igetl(&tempdmap.tmusic_xfade_out, f))
15303 {
15304 return 0;
15305 }
15306 }
15307 }
15308 DMaps[index] = tempdmap;
15309
15310 return 1;
15311 }
15312
15313 int32_t onDmaps()
15314 {
15315 DMapListerDialog(0).show();
15316 return D_O_K;
15317 }
15318
15319 int32_t onMaps()
15320 {
15321 call_edit_map_settings(Map.getCurrMap());
15322 return D_O_K;
15323 }
15324
15325 int32_t onMidis()
15326 {
15327 stopMusic();
15328 MidiListerDialog().show();
15329 return D_O_K;
15330 }
15331
15332 static DIALOG editmusic_dlg[] =
15333 {
15334 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
15335 { jwin_win_proc, 24, 20, 273, 189, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Music Specs", NULL, NULL },
15336 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
15337 // 2
15338 { jwin_text_proc, 56, 94-16, 48, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Music:", NULL, NULL },
15339 { jwin_text_proc, 104, 94-16, 48, 8, vc(11), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
15340 { jwin_text_proc, 56, 114, 48, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Name:", NULL, NULL },
15341 { jwin_edit_proc, 104, 114-4, 160, 16, vc(12), vc(1), 0, 0, 19, 0, NULL, NULL, NULL },
15342 { jwin_text_proc, 56, 124-4+12, 56, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Volume:", NULL, NULL },
15343 { jwin_edit_proc, 120, 124-4+12-4, 32, 16, vc(12), vc(1), 0, 0, 3, 0, NULL, NULL, NULL },
15344 // 8
15345 { jwin_check_proc, 176, 124+12-4, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, (void *) "Loop", NULL, NULL },
15346 // 9
15347 { jwin_button_proc, 50, 72-24, 57, 21, vc(14), vc(1), 'l', D_EXIT, 0, 0, (void *) "&Load", NULL, NULL },
15348 { jwin_iconbutton_proc, 116, 72-24, 33, 21, vc(14), vc(1), 0, D_EXIT, BTNICON_STOPSQUARE, 0, NULL, NULL, NULL },
15349 { jwin_iconbutton_proc, 156, 72-24, 33, 21, vc(14), vc(1), 0, D_EXIT, BTNICON_ARROW_RIGHT, 0, NULL, NULL, NULL },
15350 { jwin_iconbutton_proc, 196, 72-24, 33, 21, vc(14), vc(1), 0, D_EXIT, BTNICON_ARROW_RIGHT2, 0, NULL, NULL, NULL },
15351 { jwin_iconbutton_proc, 236, 72-24, 33, 21, vc(14), vc(1), 0, D_EXIT, BTNICON_ARROW_RIGHT3, 0, NULL, NULL, NULL },
15352 // 14
15353 { jwin_text_proc, 56, 134+4+12, 48, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Start:", NULL, NULL },
15354 { jwin_edit_proc, 112, 134+12, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
15355 { jwin_text_proc, 176, 134+12+4, 56, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Loop Start:", NULL, NULL },
15356 { jwin_edit_proc, 240, 134+12, 40, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
15357 { jwin_text_proc, 176, 144+12+12, 48, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Loop End:", NULL, NULL },
15358 { jwin_edit_proc, 240, 144+12+12-4, 40, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
15359 // 20
15360 { jwin_text_proc, 176, 94-16, 48, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Position:", NULL, NULL },
15361 { jwin_text_proc, 217, 94-16, 32, 8, vc(11), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
15362 { jwin_text_proc, 176, 104-8, 48, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Length:", NULL, NULL },
15363 { jwin_text_proc, 216, 104-8, 32, 8, vc(11), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
15364 { jwin_text_proc, 56, 104-8, 48, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Time:", NULL, NULL },
15365 { jwin_text_proc, 104, 104-8, 32, 8, vc(11), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
15366 // 26
15367 { jwin_button_proc, 90, 160+12+12, 61, 21, vc(14), vc(1), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
15368 { jwin_button_proc, 170, 160+12+12, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
15369 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F1, 0, (void *) onHelp, NULL, NULL },
15370 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
15371 };
15372
15373 int32_t d_musiclist_proc(int32_t msg,DIALOG *d,int32_t c)
15374 {
15375 return jwin_list_proc(msg,d,c);
15376 }
15377
15378 12 static ListData enhancedmusic_list(enhancedmusiclist, &font);
15379
15380 static DIALOG selectmusic_dlg[] =
15381 {
15382 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
15383 12 { jwin_win_proc, 24, 20, 273, 189, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Select Enhanced Music", NULL, NULL },
15384 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
15385 12 { d_musiclist_proc, 31, 44, 164, (1+16)*8, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, D_EXIT, 0, 0, (void *) &enhancedmusic_list, NULL, NULL },
15386 12 { jwin_button_proc, 90, 160+12+12, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Edit", NULL, NULL },
15387 12 { jwin_button_proc, 170, 160+12+12, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Done", NULL, NULL },
15388 12 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, KEY_DEL, (void *) close_dlg, NULL, NULL },
15389 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
15390 };
15391
15392 const char *warptypelist(int32_t index, int32_t *list_size)
15393 {
15394 if(index>=0)
15395 {
15396 if(index>=MAXWARPTYPES)
15397 index=MAXWARPTYPES-1;
15398
15399 return warptype_string[index];
15400 }
15401
15402 *list_size=MAXWARPTYPES;
15403 // *list_size=6;
15404 return NULL;
15405 }
15406
15407 const char *warpeffectlist(int32_t index, int32_t *list_size)
15408 {
15409 if(index>=0)
15410 {
15411 if(index>=MAXWARPEFFECTS)
15412 index=MAXWARPEFFECTS-1;
15413
15414 return warpeffect_string[index];
15415 }
15416
15417 *list_size=MAXWARPEFFECTS;
15418 return NULL;
15419 }
15420
15421 static int32_t warp1_list[] =
15422 {
15423 2,3,4,5,6,7,8,9,10,11,12,13,53,54,63,67,-1
15424 };
15425
15426 static int32_t warp2_list[] =
15427 {
15428 17,18,19,20,21,22,23,24,25,26,27,28,55,56,64,68,-1
15429 };
15430
15431 static int32_t warp3_list[] =
15432 {
15433 29,30,31,32,33,34,35,36,37,38,39,40,57,58,65,69,-1
15434 };
15435
15436 static int32_t warp4_list[] =
15437 {
15438 41,42,43,44,45,46,47,48,49,50,51,52,59,60,66,70,-1
15439 };
15440
15441 static TABPANEL warp_tabs[] =
15442 {
15443 // (text)
15444 { (char *)"A", D_SELECTED, warp1_list, 0, NULL },
15445 { (char *)"B", 0, warp2_list, 0, NULL },
15446 { (char *)"C", 0, warp3_list, 0, NULL },
15447 { (char *)"D", 0, warp4_list, 0, NULL },
15448 { NULL, 0, NULL, 0, NULL }
15449 };
15450
15451 int32_t onTileWarpIndex(int32_t index)
15452 {
15453 int32_t i=-1;
15454
15455 while(warp_tabs[++i].text != NULL)
15456 warp_tabs[i].flags = (i==index ? D_SELECTED : 0);
15457
15458 onTileWarp();
15459 return D_O_K;
15460 }
15461
15462 static char warpr_buf[10];
15463 const char *warprlist(int32_t index, int32_t *list_size)
15464 {
15465 if(index>=0)
15466 {
15467 bound(index,0,3);
15468 sprintf(warpr_buf,"%c",index+0x41);
15469 return warpr_buf;
15470 }
15471
15472 *list_size=4;
15473 return NULL;
15474 }
15475
15476 int32_t d_wflag_proc(int32_t msg,DIALOG *d,int32_t c);
15477
15478 12 static ListData warp_dlg_list(warptypelist, &font);
15479 12 static ListData warp_ret_list(warprlist, &font);
15480
15481 int32_t d_warpdestscrsel_proc(int32_t msg,DIALOG *d,int32_t c)
15482 {
15483 if(msg == MSG_START)
15484 {
15485 d->d1 = -1; //cached val
15486 d->d2 = -1; //cached dmap
15487 d->fg = 0; //cached 'force_16'
15488 }
15489 char* buf = (char*)d->dp;
15490 vector<DIALOG*>* dlgs = (vector<DIALOG*>*)d->dp2;
15491 int* dmap_ptr = (int*) d->dp3;
15492 if(!(buf && dmap_ptr))
15493 return D_O_K;
15494 bool is_overworld = ((DMaps[*dmap_ptr].type&dmfTYPE)==dmOVERW);
15495 int scrw = is_overworld ? 16 : 8, scrh = 9;
15496 const int max = 0x87;
15497 int bufval = zc_xtoi(buf);
15498 int val = vbound(bufval,0,max);
15499 auto& dm = DMaps[*dmap_ptr];
15500 auto val_offset = dm.xoff < 0 ? -dm.xoff : 0;
15501 bool force_16 = d->fg;
15502 if(!is_overworld)
15503 {
15504 if((val&0xF) >= 0x8)
15505 force_16 = true;
15506 else if((val&0xF) < val_offset && (val&0xF0) < 0x80)
15507 force_16 = true;
15508 }
15509 if(force_16) //can't bound, some quests need to warp out of bounds... -Em
15510 {
15511 scrw = 16; //just force show the larger grid instead
15512 val_offset = 0;
15513 }
15514
15515 int xscl = d->w/scrw;
15516 int yscl = d->h/scrh;
15517
15518 int ret = D_O_K;
15519 bool redraw = false;
15520 if(d->d1 != val)
15521 {
15522 redraw = true;
15523 d->d1 = val;
15524 }
15525 if(bufval != val)
15526 {
15527 redraw = true;
15528 sprintf(buf, "%X", val);
15529 }
15530 if(d->d2 != *dmap_ptr)
15531 {
15532 redraw = true;
15533 d->d2 = *dmap_ptr;
15534 }
15535 switch(msg)
15536 {
15537 case MSG_WANTFOCUS:
15538 ret = D_WANTFOCUS;
15539 break;
15540 case MSG_CLICK:
15541 {
15542 d->fg = force_16 ? 1 : 0;
15543 bool redraw2 = false;
15544 while(gui_mouse_b())
15545 {
15546 if(redraw2)
15547 {
15548 broadcast_dialog_message(MSG_DRAW, 0);
15549 redraw2 = false;
15550 }
15551 if(!d->fg && (gui_mouse_b()&2))
15552 {
15553 scrw = 16;
15554 xscl = d->w/scrw;
15555 yscl = d->h/scrh;
15556 val_offset = 0;
15557 d->fg = 1;
15558 redraw2 = true;
15559 }
15560 custom_vsync();
15561 if(!mouse_in_rect(d->x,d->y,d->w,d->h))
15562 continue;
15563 int mx = gui_mouse_x()-d->x, my = gui_mouse_y()-d->y;
15564 int y = vbound(my/yscl,0,scrh-1);
15565 auto offs = y==8 ? 0 : val_offset;
15566 int x = vbound(mx/xscl,offs,scrw-1);
15567 auto val2 = (y*16)+x;
15568 if(val2 > max) //out of bounds in the bottom-right
15569 continue;
15570 val = val2;
15571 if(d->d1 != val)
15572 {
15573 d->d1 = val;
15574 sprintf(buf, "%02X", val);
15575 redraw2 = true;
15576 }
15577 }
15578 redraw = true;
15579 d->fg = 0;
15580 break;
15581 }
15582 case MSG_DRAW:
15583 {
15584 rectfill(screen,d->x,d->y,d->x+d->w-1,d->y+d->h-1,jwin_pal[jcBOX]);
15585 jwin_draw_frame(screen, d->x-2, d->y-2, d->w+4, d->h+4, FR_MENU);
15586 for(int yind = 0; yind < scrh; ++yind)
15587 {
15588 auto gr = (yind < 8 ? dm.grid[yind] : 0);
15589 for(int xind = (yind == 8 ? 0 : val_offset); xind < scrw; ++xind)
15590 {
15591 int screen_index = xind+(yind*16);
15592 if(screen_index > max)
15593 continue;
15594 int fr = FR_MENU;
15595 if(screen_index == d->d1)
15596 fr = FR_GREEN;
15597 else if(!is_overworld && xind < 8 && (gr&(1<<(8-xind-1))))
15598 fr = FR_MENU_INV;
15599 jwin_draw_frame(screen, d->x+(xind*xscl), d->y+(yind*yscl), xscl, yscl, fr);
15600 }
15601 }
15602 break;
15603 }
15604 case MSG_XCHAR:
15605 {
15606 bool on_80 = (val&0xF0) == 0x80;
15607 switch(c>>8)
15608 {
15609 case KEY_UP:
15610 if((val&0xF0) && !(val_offset && on_80 && (val&0xF) < val_offset))
15611 {
15612 val -= 0x10;
15613 redraw = true;
15614 }
15615 ret |= D_USED_CHAR;
15616 break;
15617 case KEY_DOWN:
15618 if((val&0xF0) < ((val&0xF) < 0x8 ? 0x80 : 0x70))
15619 {
15620 val += 0x10;
15621 redraw = true;
15622 }
15623 ret |= D_USED_CHAR;
15624 break;
15625 case KEY_LEFT:
15626 if((val&0xF) > (on_80 ? 0 : val_offset))
15627 {
15628 --val;
15629 redraw = true;
15630 }
15631 ret |= D_USED_CHAR;
15632 break;
15633 case KEY_RIGHT:
15634 if((val&0xF) < scrw-1 && val < 0x87)
15635 {
15636 ++val;
15637 redraw = true;
15638 }
15639 ret |= D_USED_CHAR;
15640 break;
15641 }
15642 if(redraw)
15643 sprintf(buf, "%02X", val);
15644 break;
15645 }
15646 }
15647 if(redraw)
15648 {
15649 if(msg == MSG_IDLE)
15650 broadcast_dialog_message(MSG_DRAW,0);
15651 else
15652 {
15653 d->d1 = d->d2 = -1;
15654 object_message(d,MSG_IDLE,0);
15655 }
15656 }
15657
15658 return ret;
15659 }
15660
15661 int32_t tilewarpdmapxy[6] = {170,38,170,18,170,27};
15662 static DIALOG tilewarp_dlg[] =
15663 {
15664 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
15665 12 { jwin_win_proc, 0, 0, 302, 178, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
15666 12 { jwin_rtext_proc, 89, 43, 40, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Type:", NULL, NULL },
15667 12 { jwin_rtext_proc, 57, 62, 40, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "DMap:", NULL, NULL },
15668 12 { jwin_rtext_proc, 57, 80, 64, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Screen: 0x", NULL, NULL },
15669 12 { jwin_droplist_proc, 91, 38, 193, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &warp_dlg_list, NULL, NULL },
15670 //5
15671 12 { d_dropdmaplist_proc, 59, 57, 225, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &dmap_list, NULL, tilewarpdmapxy },
15672 12 { jwin_hexedit_proc, 59, 76, 24, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
15673 12 { jwin_button_proc, 61, 152, 41, 21, vc(14), vc(1), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
15674 12 { jwin_button_proc, 121, 152, 41, 21, vc(14), vc(1), 'g', D_EXIT, 0, 0, (void *) "&Go", NULL, NULL },
15675 12 { jwin_button_proc, 181, 152, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
15676 //10
15677 12 { jwin_rtext_proc, 82, 95, 100, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Use Warp Return:", NULL, NULL },
15678 12 { jwin_droplist_proc, 10, 105, 72, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &warp_ret_list, NULL, NULL },
15679 12 { jwin_check_proc, 10, 125, 129, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Combos Carry Over", NULL, NULL },
15680 12 { d_warpdestscrsel_proc, 90, 76, 8*16, 8*9, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
15681 12 { jwin_button_proc, 59, 21, 50, 14, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "A", NULL, NULL },
15682 //15
15683 12 { jwin_button_proc, 109, 21, 50, 14, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "B", NULL, NULL },
15684 12 { jwin_button_proc, 159, 21, 50, 14, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "C", NULL, NULL },
15685 12 { jwin_button_proc, 209, 21, 50, 14, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "D", NULL, NULL },
15686 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
15687 };
15688
15689 int32_t sidewarpdmapxy[6] = {170,38,170,18,170,27};
15690 static DIALOG sidewarp_dlg[] =
15691 {
15692 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
15693 12 { jwin_win_proc, 0, 0, 302, 178, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
15694 12 { jwin_rtext_proc, 89, 43, 40, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Type:", NULL, NULL },
15695 12 { jwin_rtext_proc, 57, 62, 40, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "DMap:", NULL, NULL },
15696 12 { jwin_rtext_proc, 57, 80, 64, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Screen: 0x", NULL, NULL },
15697 12 { jwin_droplist_proc, 91, 38, 193, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &warp_dlg_list, NULL, NULL },
15698 //5
15699 12 { d_dropdmaplist_proc, 59, 57, 225, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &dmap_list, NULL, tilewarpdmapxy },
15700 12 { jwin_hexedit_proc, 59, 76, 24, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
15701 12 { jwin_button_proc, 61, 152, 41, 21, vc(14), vc(1), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
15702 12 { jwin_button_proc, 121, 152, 41, 21, vc(14), vc(1), 'g', D_EXIT, 0, 0, (void *) "&Go", NULL, NULL },
15703 12 { jwin_button_proc, 181, 152, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
15704 //10
15705 12 { jwin_rtext_proc, 82, 95, 100, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Use Warp Return:", NULL, NULL },
15706 12 { jwin_droplist_proc, 10, 105, 72, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &warp_ret_list, NULL, NULL },
15707 12 { jwin_check_proc, 10, 125, 129, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Combos Carry Over", NULL, NULL },
15708 12 { d_warpdestscrsel_proc, 90, 76, 8*16, 8*9, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
15709 12 { jwin_button_proc, 59, 21, 50, 14, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "A", NULL, NULL },
15710 //15
15711 12 { jwin_button_proc, 109, 21, 50, 14, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "B", NULL, NULL },
15712 12 { jwin_button_proc, 159, 21, 50, 14, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "C", NULL, NULL },
15713 12 { jwin_button_proc, 209, 21, 50, 14, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "D", NULL, NULL },
15714 // 18
15715 12 { d_wflag_proc, 18, 17, 15, 8, vc(4), vc(0), 0, 0, 1, 0, NULL, NULL, NULL },
15716 12 { d_wflag_proc, 18, 47, 15, 8, vc(4), vc(0), 0, 0, 1, 0, NULL, NULL, NULL },
15717 // 20
15718 12 { d_wflag_proc, 8, 27, 8, 15, vc(4), vc(0), 0, 0, 1, 0, NULL, NULL, NULL },
15719 12 { d_wflag_proc, 37, 27, 8, 15, vc(4), vc(0), 0, 0, 1, 0, NULL, NULL, NULL },
15720
15721 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
15722 };
15723
15724 int32_t warpringxy[6] = {170,38,170,18,170,27};
15725 static DIALOG warpring_warp_dlg[] =
15726 {
15727 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
15728 12 { jwin_win_proc, 0, 0, 302, 145, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
15729 12 { jwin_rtext_proc, 57, 25, 40, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "DMap:", NULL, NULL },
15730 12 { jwin_rtext_proc, 57, 46, 64, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Screen: 0x", NULL, NULL },
15731 12 { d_dropdmaplist_proc, 59, 19, 225, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &dmap_list, NULL, warpringxy },
15732 12 { jwin_hexedit_proc, 59, 39, 24, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
15733 // 5
15734 12 { jwin_button_proc, 61, 115, 41, 21, vc(14), vc(1), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
15735 12 { jwin_button_proc, 121, 115, 41, 21, vc(14), vc(1), 'g', D_EXIT, 0, 0, (void *) "&Go", NULL, NULL },
15736 12 { jwin_button_proc, 181, 115, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
15737 12 { d_warpdestscrsel_proc, 90, 39, 8*16, 8*9, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
15738
15739 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
15740 };
15741
15742 // Side warp flag procedure
15743 int32_t d_wflag_proc(int32_t msg,DIALOG *d,int32_t)
15744 {
15745 int32_t ret = D_O_K;
15746 switch(msg)
15747 {
15748 case MSG_DRAW:
15749 {
15750 int32_t c2=(d->flags&D_SELECTED)?d->fg:d->bg;
15751
15752 if(d->d1==1)
15753 {
15754 jwin_draw_frame(screen,d->x,d->y,d->w,d->h, FR_DEEP);
15755 rectfill(screen,d->x+2, d->y+2, d->x+d->w-3, d->y+d->h-3,c2);
15756
15757 if(d->flags&D_SELECTED)
15758 {
15759 int32_t e=d->d2&3;
15760
15761 if(d->w>d->h)
15762 textprintf_centre_ex(screen,get_zc_font(font_lfont_l), d->x+(d->w/2),d->y,jwin_pal[jcBOXFG],-1,"%c",e+0x41);
15763 else
15764 textprintf_centre_ex(screen,get_zc_font(font_lfont_l), d->x+(d->w/2),d->y+(d->h/2)-4,jwin_pal[jcBOXFG],-1,"%c",e+0x41);
15765 }
15766
15767 }
15768 else
15769 {
15770 rectfill(screen,d->x, d->y, d->x+d->w-1, d->y+d->h-1,c2);
15771 }
15772 }
15773 break;
15774
15775 case MSG_CLICK:
15776 {
15777 if(d->flags & D_DISABLED)
15778 return D_O_K;
15779 bool rclick = gui_mouse_b() & 2;
15780 if(d->d1==1)
15781 {
15782 if(!(d->flags&D_SELECTED))
15783 {
15784 d->flags |= D_SELECTED;
15785 d->d2 &= 0x80;
15786 if (rclick)
15787 d->d2 |= 3;
15788 }
15789 else
15790 {
15791 if((d->d2&3) == (rclick?0:3))
15792 {
15793 d->flags ^= D_SELECTED;
15794 d->d2 &= 0x80;
15795 }
15796 else
15797 {
15798 int32_t f = d->d2&3;
15799 d->d2 &= 0x80;
15800 f += rclick ? -1 : 1;
15801 d->d2 |= f;
15802 }
15803 }
15804 }
15805 else
15806 {
15807 d->flags^=D_SELECTED;
15808 }
15809
15810 int32_t c2=(d->flags&D_SELECTED)?d->fg:d->bg;
15811
15812 if(d->d1==1)
15813 {
15814 jwin_draw_frame(screen,d->x,d->y,d->w,d->h, FR_DEEP);
15815 rectfill(screen,d->x+2, d->y+2, d->x+d->w-3, d->y+d->h-3,c2);
15816
15817 if(d->flags&D_SELECTED)
15818 {
15819 int32_t e=d->d2&3;
15820
15821 if(d->w>d->h)
15822 textprintf_centre_ex(screen,get_zc_font(font_lfont_l),d->x+(d->w/2),d->y,jwin_pal[jcBOXFG],-1,"%c",e+0x41);
15823 else
15824 textprintf_centre_ex(screen,get_zc_font(font_lfont_l),d->x+(d->w/2),d->y+(d->h/2)-4,jwin_pal[jcBOXFG],-1,"%c",e+0x41);
15825 }
15826 }
15827 else
15828 {
15829 rectfill(screen,d->x, d->y, d->x+d->w-1, d->y+d->h-1,c2);
15830 }
15831
15832
15833 while(gui_mouse_b())
15834 {
15835 /* do nothing */
15836 rest(1);
15837 }
15838 ret = D_REDRAWME;
15839 }
15840 break;
15841 }
15842
15843 return ret;
15844 }
15845
15846 int32_t d_dmapscrsel_proc(int32_t msg,DIALOG *d,int32_t c)
15847 {
15848 //these are here to bypass compiler warnings about unused arguments
15849 c=c;
15850
15851 int32_t ret = D_O_K;
15852
15853 switch(msg)
15854 {
15855 case MSG_CLICK:
15856 sprintf((char*)((d+2)->dp),"%X%X",vbound((gui_mouse_y()-d->y)/4,0,7),vbound((gui_mouse_x()-d->x)/(((DMaps[(d-1)->d1].type&dmfTYPE)==1)?4:8),0,(((DMaps[(d-1)->d1].type&dmfTYPE)==1)?15:7)));
15857 object_message(d+2, MSG_DRAW, 0);
15858 break;
15859 }
15860
15861 return ret;
15862 }
15863
15864 int32_t warpdestsel_x=-1;
15865 int32_t warpdestsel_y=-1;
15866 int32_t warpdestmap=-1;
15867 int32_t warpdestscr=-1;
15868
15869 int32_t jwin_minibutton_proc(int32_t msg,DIALOG *d,int32_t c)
15870 {
15871 switch(msg)
15872 {
15873 case MSG_DRAW:
15874 jwin_draw_text_button(screen, d->x, d->y, d->w, d->h, (char*)d->dp, d->flags, false);
15875 return D_O_K;
15876 break;
15877 }
15878
15879 return jwin_button_proc(msg,d,c);
15880 }
15881
15882 int32_t d_triggerbutton_proc(int32_t msg,DIALOG *d,int32_t c)
15883 {
15884 static BITMAP *dummy=create_bitmap_ex(8, 1, 1);
15885
15886 switch(msg)
15887 {
15888 case MSG_START:
15889 d->w=gui_textout_ln(dummy, font, (uint8_t *)d->dp, 0, 0, jwin_pal[jcMEDDARK], -1, 0)+4;
15890 d->h=text_height(font)+5;
15891 break;
15892
15893 case MSG_GOTFOCUS:
15894 d->flags&=~D_GOTFOCUS;
15895 break;
15896
15897 }
15898
15899 return jwin_minibutton_proc(msg,d,c);
15900 }
15901
15902 int32_t d_alltriggerbutton_proc(int32_t msg,DIALOG *d,int32_t c)
15903 {
15904 DIALOG *temp_d;
15905 int32_t ret=d_triggerbutton_proc(msg,d,c);
15906
15907 switch(msg)
15908 {
15909 case MSG_CLICK:
15910 temp_d=d-1;
15911
15912 while(temp_d->proc==d_triggerbutton_proc)
15913 {
15914 temp_d->flags&=~D_SELECTED;
15915 temp_d->flags|=D_DIRTY;
15916
15917 if(d->flags&D_SELECTED)
15918 {
15919 temp_d->flags|=D_SELECTED;
15920 }
15921
15922 --temp_d;
15923 }
15924
15925 break;
15926 }
15927
15928 return ret;
15929 }
15930
15931 int32_t d_ticsedit_proc(int32_t msg,DIALOG *d,int32_t c)
15932 {
15933 int32_t ret = jwin_edit_proc(msg,d,c);
15934
15935 if(msg==MSG_DRAW)
15936 {
15937 int32_t tics=vbound(atoi((char*)d->dp),0,65535);
15938 sprintf((char*)(d+1)->dp,"%s %s",ticksstr(tics),tics==0?"(No Timed Warp)":" ");
15939 object_message(d+1,MSG_DRAW,c);
15940 }
15941
15942 return ret;
15943 }
15944
15945 12 static ListData warp_effect_list(warpeffectlist,&font);
15946
15947 struct tw_data
15948 {
15949 int twscr[4], twtype[4], twdmap[4], wret[4];
15950 byte oflags;
15951 optional<uint> loaded;
15952
15953 tw_data(mapscr* scr) {load_scr(scr);}
15954 void load_scr(mapscr* scr)
15955 {
15956 oflags = scr->tilewarpoverlayflags;
15957 for(int q = 0; q < 4; ++q)
15958 {
15959 twscr[q] = scr->tilewarpscr[q];
15960 twtype[q] = scr->tilewarptype[q];
15961 twdmap[q] = scr->tilewarpdmap[q];
15962 wret[q] = (scr->warpreturnc >> (2*q))&3;
15963 }
15964 loaded.reset();
15965 }
15966 void save_scr(mapscr* scr)
15967 {
15968 saved=false;
15969 scr->tilewarpoverlayflags = oflags;
15970 scr->warpreturnc = scr->warpreturnc & 0xFF00;
15971 for(int q = 0; q < 4; ++q)
15972 {
15973 scr->tilewarpscr[q] = twscr[q];
15974 scr->tilewarptype[q] = twtype[q];
15975 scr->tilewarpdmap[q] = twdmap[q];
15976 scr->warpreturnc |= wret[q] << (2*q);
15977 }
15978 }
15979
15980 void load(uint ind)
15981 {
15982 if(ind >= 4) return;
15983 loaded = ind;
15984 tilewarp_dlg[4].d1 = twtype[ind];
15985 tilewarp_dlg[5].d1 = twdmap[ind];
15986 char* buf = (char*)tilewarp_dlg[6].dp;
15987 sprintf(buf,"%02X",twscr[ind]);
15988 tilewarp_dlg[11].d1 = wret[ind];
15989 SETFLAG(tilewarp_dlg[12].flags, D_SELECTED, get_bit(&oflags,ind));
15990 for(int q = 0; q < 4; ++q)
15991 SETFLAG(tilewarp_dlg[14+q].flags,(D_SELECTED|D_DISABLED),q==ind);
15992 }
15993 void save(uint ind)
15994 {
15995 if(ind >= 4) return;
15996 twtype[ind] = tilewarp_dlg[4].d1;
15997 twdmap[ind] = tilewarp_dlg[5].d1;
15998 char* buf = (char*)tilewarp_dlg[6].dp;
15999 twscr[ind] = vbound(zc_xtoi(buf),0x00,0x87);
16000 wret[ind] = tilewarp_dlg[11].d1;
16001 set_bit(&oflags, ind, tilewarp_dlg[12].flags & D_SELECTED);
16002 }
16003 void save()
16004 {
16005 if(loaded)
16006 save(*loaded);
16007 }
16008 void swap(uint ind)
16009 {
16010 if(ind >= 4) return;
16011 if(loaded)
16012 {
16013 save(*loaded);
16014 if(*loaded == ind)
16015 return;
16016 }
16017 load(ind);
16018 }
16019 };
16020 int32_t onTileWarp()
16021 {
16022 restore_mouse();
16023 tilewarp_dlg[0].dp=(void *) "Tile Warp";
16024 tilewarp_dlg[0].dp2=get_zc_font(font_lfont);
16025
16026 mapscr* mptr = Map.CurrScr();
16027 char buf[10];
16028 tilewarp_dlg[6].dp=buf;
16029 tilewarp_dlg[13].dp = buf;
16030 tilewarp_dlg[13].dp3 = &tilewarp_dlg[5].d1;
16031
16032 vector<DIALOG*> dlgs;
16033 dlgs.push_back(&tilewarp_dlg[5]);
16034 dlgs.push_back(&tilewarp_dlg[6]);
16035 tilewarp_dlg[13].dp2 = &dlgs;
16036
16037 tw_data data(mptr);
16038 data.load(0);
16039
16040 dmap_list_size=MAXDMAPS;
16041 dmap_list_zero=true;
16042
16043 large_dialog(tilewarp_dlg);
16044
16045 bool running = true;
16046 int ret;
16047 do
16048 {
16049 ret = do_zqdialog(tilewarp_dlg,-1);
16050 switch(ret)
16051 {
16052 // OK, GO
16053 case 7: case 8:
16054 running = false;
16055 data.save();
16056 data.save_scr(mptr);
16057 refresh(rMENU);
16058 break;
16059 //Cancel
16060 case 9:
16061 running = false;
16062 break;
16063 //A,B,C,D
16064 case 14: case 15: case 16: case 17:
16065 data.swap(ret-14);
16066 break;
16067 }
16068 }
16069 while(running);
16070
16071 if(ret==8) //GO
16072 {
16073 int32_t index = *data.loaded;
16074
16075 FlashWarpSquare = -1;
16076 int32_t tm = Map.getCurrMap();
16077 int32_t ts = Map.getCurrScr();
16078 int32_t thistype = mptr->tilewarptype[index];
16079 Map.dowarp(0,index);
16080
16081 if((ts!=Map.getCurrScr() || tm!=Map.getCurrMap()) && thistype != wtCAVE && thistype != wtSCROLL)
16082 {
16083 FlashWarpSquare = (TheMaps[tm*MAPSCRS+ts].warpreturnc>>(index*2))&3;
16084 FlashWarpClk = 32;
16085 }
16086
16087 refresh(rALL);
16088 }
16089
16090 return D_O_K;
16091 }
16092
16093 struct sw_data
16094 {
16095 int swscr[4], swtype[4], swdmap[4], wret[4];
16096 byte oflags;
16097 optional<uint> loaded;
16098
16099 sw_data(mapscr* scr) {load_scr(scr);}
16100 void load_scr(mapscr* scr)
16101 {
16102 oflags = scr->sidewarpoverlayflags;
16103 for(int q = 0; q < 4; ++q)
16104 {
16105 swscr[q] = scr->sidewarpscr[q];
16106 swtype[q] = scr->sidewarptype[q];
16107 swdmap[q] = scr->sidewarpdmap[q];
16108 wret[q] = (scr->warpreturnc >> (2*(q+4)))&3;
16109 }
16110 loaded.reset();
16111
16112 for(int32_t i=0; i<4; i++)
16113 {
16114 sidewarp_dlg[18+i].d2 = 0x80;
16115 if(scr->flags2&(1<<i))
16116 {
16117 sidewarp_dlg[18+i].flags = D_SELECTED ;
16118 sidewarp_dlg[18+i].d2 |= (scr->sidewarpindex>>(2*i))&3;
16119 }
16120 else
16121 {
16122 sidewarp_dlg[18+i].flags = 0;
16123 }
16124 }
16125 }
16126 void save_scr(mapscr* scr)
16127 {
16128 saved=false;
16129 scr->sidewarpoverlayflags = oflags;
16130 scr->warpreturnc = scr->warpreturnc & 0x00FF;
16131 for(int q = 0; q < 4; ++q)
16132 {
16133 scr->sidewarpscr[q] = swscr[q];
16134 scr->sidewarptype[q] = swtype[q];
16135 scr->sidewarpdmap[q] = swdmap[q];
16136 scr->warpreturnc |= wret[q] << (2*(q+4));
16137 }
16138
16139 scr->flags2 &= ~0xF;
16140 scr->sidewarpindex = 0;
16141 for(int32_t i=0; i<4; i++)
16142 {
16143 if(sidewarp_dlg[18+i].flags & D_SELECTED)
16144 scr->flags2 |= 1<<i;
16145 scr->sidewarpindex |= (sidewarp_dlg[18+i].d2&3) << (i*2);
16146 }
16147 }
16148
16149 void load(uint ind)
16150 {
16151 if(ind >= 4) return;
16152 loaded = ind;
16153 sidewarp_dlg[4].d1 = swtype[ind];
16154 sidewarp_dlg[5].d1 = swdmap[ind];
16155 char* buf = (char*)sidewarp_dlg[6].dp;
16156 sprintf(buf,"%02X",swscr[ind]);
16157 sidewarp_dlg[11].d1 = wret[ind];
16158 SETFLAG(sidewarp_dlg[12].flags, D_SELECTED, get_bit(&oflags,ind));
16159 for(int q = 0; q < 4; ++q)
16160 SETFLAG(sidewarp_dlg[14+q].flags,(D_SELECTED|D_DISABLED),q==ind);
16161 }
16162 void save(uint ind)
16163 {
16164 if(ind >= 4) return;
16165 swtype[ind] = sidewarp_dlg[4].d1;
16166 swdmap[ind] = sidewarp_dlg[5].d1;
16167 char* buf = (char*)sidewarp_dlg[6].dp;
16168 swscr[ind] = vbound(zc_xtoi(buf),0x00,0x87);
16169 wret[ind] = sidewarp_dlg[11].d1;
16170 set_bit(&oflags, ind, sidewarp_dlg[12].flags & D_SELECTED);
16171 }
16172 void save()
16173 {
16174 if(loaded)
16175 save(*loaded);
16176 }
16177 void swap(uint ind)
16178 {
16179 if(ind >= 4) return;
16180 if(loaded)
16181 {
16182 save(*loaded);
16183 if(*loaded == ind)
16184 return;
16185 }
16186 load(ind);
16187 }
16188 };
16189 int32_t onSideWarp()
16190 {
16191 restore_mouse();
16192 sidewarp_dlg[0].dp=(void *) "Side Warp";
16193 sidewarp_dlg[0].dp2=get_zc_font(font_lfont);
16194
16195 mapscr* mptr = Map.CurrScr();
16196 char buf[10];
16197 sidewarp_dlg[6].dp=buf;
16198 sidewarp_dlg[13].dp = buf;
16199 sidewarp_dlg[13].dp3 = &sidewarp_dlg[5].d1;
16200
16201 vector<DIALOG*> dlgs;
16202 dlgs.push_back(&sidewarp_dlg[5]);
16203 dlgs.push_back(&sidewarp_dlg[6]);
16204 sidewarp_dlg[13].dp2 = &dlgs;
16205
16206 sw_data data(mptr);
16207 data.load(0);
16208
16209 dmap_list_size=MAXDMAPS;
16210 dmap_list_zero=true;
16211
16212 large_dialog(sidewarp_dlg);
16213
16214 bool running = true;
16215 int ret;
16216 do
16217 {
16218 ret = do_zqdialog(sidewarp_dlg,-1);
16219 switch(ret)
16220 {
16221 // OK, GO
16222 case 7: case 8:
16223 running = false;
16224 data.save();
16225 data.save_scr(mptr);
16226 refresh(rMENU);
16227 break;
16228 //Cancel
16229 case 9:
16230 running = false;
16231 break;
16232 //A,B,C,D
16233 case 14: case 15: case 16: case 17:
16234 data.swap(ret-14);
16235 break;
16236 }
16237 }
16238 while(running);
16239
16240 if(ret==8) //GO
16241 {
16242 int32_t index = *data.loaded;
16243
16244 FlashWarpSquare = -1;
16245 int32_t tm = Map.getCurrMap();
16246 int32_t ts = Map.getCurrScr();
16247
16248 int32_t thistype = mptr->sidewarptype[index];
16249 Map.dowarp(1,index);
16250
16251 if((ts!=Map.getCurrScr() || tm!=Map.getCurrMap()) && thistype != wtSCROLL)
16252 {
16253 FlashWarpSquare = (TheMaps[tm*MAPSCRS+ts].warpreturnc>>(8+index*2))&3;
16254 FlashWarpClk = 0x20;
16255 }
16256
16257 refresh(rALL);
16258 }
16259
16260 return D_O_K;
16261 }
16262
16263
16264
16265 const char *dirlist(int32_t index, int32_t *list_size)
16266 {
16267 if(index>=0)
16268 {
16269 if(index>3)
16270 index=3;
16271
16272 return mazedirstr[index];
16273 }
16274
16275 *list_size=4;
16276 return NULL;
16277 }
16278
16279 12 static ListData path_dlg_list(dirlist, &font);
16280
16281 static const char *wipestr[] = {"None", "Circle", "Oval", "Triangle", "SMAS", "Fade Black"};
16282 // enum {bosCIRCLE=0, bosOVAL, bosTRIANGLE, bosSMAS, bosFADEBLACK, bosMAX};
16283 const char *wipelist(int32_t index, int32_t *list_size)
16284 {
16285 if(index>=0)
16286 {
16287 if(index>5)
16288 index=5;
16289
16290 return wipestr[index];
16291 }
16292
16293 *list_size=6;
16294 return NULL;
16295 }
16296
16297 12 static ListData wipe_effect_dlg_list(wipelist, &font);
16298
16299 static DIALOG path_dlg[] =
16300 {
16301 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
16302 12 { jwin_win_proc, 80, 57, 161, 182, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Maze Path", NULL, NULL },
16303 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
16304 12 { jwin_text_proc, 94, 106, 192, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "1st", NULL, NULL },
16305 12 { jwin_text_proc, 94, 124, 192, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "2nd", NULL, NULL },
16306 12 { jwin_text_proc, 94, 142, 192, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "3rd", NULL, NULL },
16307 12 { jwin_text_proc, 94, 160, 192, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "4th", NULL, NULL },
16308 12 { jwin_text_proc, 94, 178, 192, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Exit", NULL, NULL },
16309 12 { jwin_text_proc, 94, 196, 192, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Wipe effect", NULL, NULL },
16310 12 { jwin_droplist_proc, 140, 102, 80+1, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &path_dlg_list, NULL, NULL },
16311 12 { jwin_droplist_proc, 140, 120, 80+1, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &path_dlg_list, NULL, NULL },
16312 12 { jwin_droplist_proc, 140, 138, 80+1, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &path_dlg_list, NULL, NULL },
16313 12 { jwin_droplist_proc, 140, 156, 80+1, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &path_dlg_list, NULL, NULL },
16314 12 { jwin_droplist_proc, 140, 174, 80+1, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &path_dlg_list, NULL, NULL },
16315 12 { jwin_droplist_proc, 140, 192, 80+1, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &wipe_effect_dlg_list, NULL, NULL },
16316 12 { jwin_button_proc, 90, 212, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
16317 12 { jwin_button_proc, 170, 212, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
16318 12 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F1, 0, (void *) onHelp, NULL, NULL },
16319 12 { jwin_text_proc, 87, 82, 192, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "A Lost Woods-style maze screen", NULL, NULL },
16320 12 { jwin_text_proc, 87, 92, 192, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "with a normal and secret exit.", NULL, NULL },
16321 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
16322 };
16323
16324 int32_t onPath()
16325 {
16326 restore_mouse();
16327 path_dlg[0].dp2=get_zc_font(font_lfont);
16328
16329 for(int32_t i=0; i<4; i++)
16330 path_dlg[i+8].d1 = Map.CurrScr()->path[i];
16331
16332 path_dlg[12].d1 = Map.CurrScr()->exitdir;
16333 path_dlg[13].d1 = Map.CurrScr()->maze_transition_wipe;
16334
16335 large_dialog(path_dlg);
16336
16337 int32_t ret;
16338
16339 do
16340 {
16341 ret=do_zqdialog(path_dlg,8);
16342
16343 if(ret==14)
16344 {
16345 for(int32_t i=0; i<4; i++)
16346 {
16347 if(path_dlg[i+8].d1 == path_dlg[12].d1)
16348 {
16349 if(jwin_alert("Exit Problem","One of the path's directions is","also the normal Exit direction! Continue?",NULL,"Yes","No",'y','n',get_zc_font(font_lfont))==2)
16350 ret = -1;
16351
16352 break;
16353 }
16354 }
16355 }
16356 }
16357 while(ret == -1);
16358
16359 if(ret==14)
16360 {
16361 saved=false;
16362
16363 for(int32_t i=0; i<4; i++)
16364 Map.CurrScr()->path[i] = path_dlg[i+8].d1;
16365
16366 Map.CurrScr()->exitdir = path_dlg[12].d1;
16367 Map.CurrScr()->maze_transition_wipe = path_dlg[13].d1;
16368
16369 if(!(Map.CurrScr()->flags&fMAZE))
16370 if(jwin_alert("Screen Flag","Turn on the 'Use Maze Path' Screen Flag?","(Go to 'Screen Data' to turn it off.)",NULL,"Yes","No",'y','n',get_zc_font(font_lfont))==1)
16371 Map.CurrScr()->flags |= fMAZE;
16372 }
16373
16374 refresh(rMAP+rMENU);
16375 return D_O_K;
16376 }
16377
16378
16379
16380 static DIALOG editinfo_dlg[] =
16381 {
16382 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
16383 12 { jwin_win_proc, 0, 10, 208, 204, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
16384 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
16385 12 { jwin_text_proc, 24, 60, 48, 8, vc(7), vc(1), 0, 0, 0, 0, (void *) "1st", NULL, NULL },
16386 12 { jwin_text_proc, 24, 106, 48, 8, vc(7), vc(1), 0, 0, 0, 0, (void *) "2nd", NULL, NULL },
16387 12 { jwin_text_proc, 24, 152, 48, 8, vc(7), vc(1), 0, 0, 0, 0, (void *) "3rd", NULL, NULL },
16388 12 { jwin_text_proc, 56, 60, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Price:", NULL, NULL },
16389 12 { jwin_text_proc, 56, 106, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Price:", NULL, NULL },
16390 12 { jwin_text_proc, 56, 152, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Price:", NULL, NULL },
16391 // 8
16392 12 { jwin_edit_proc, 86, 56, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16393 12 { d_ndroplist_proc, 56, 74, 137, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16394 12 { jwin_edit_proc, 86, 102, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16395 12 { d_ndroplist_proc, 56, 120, 137, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16396 12 { jwin_edit_proc, 86, 148, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16397 12 { d_ndroplist_proc, 56, 166, 137, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16398 12 { jwin_text_proc, 24, 42, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Name:", NULL, NULL },
16399 12 { jwin_edit_proc, 56, 38, 137, 16, vc(12), vc(1), 0, 0, 31, 0, NULL, NULL, NULL },
16400 // 16
16401 12 { jwin_button_proc, 34, 188, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
16402 12 { jwin_button_proc, 114, 188, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
16403 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
16404 };
16405
16406 void EditInfoType(int32_t index)
16407 {
16408 char ps1[6],ps2[6],ps3[6];
16409 char infoname[33];
16410 char caption[40];
16411
16412 int32_t str1, str2, str3;
16413
16414 sprintf(caption,"Info Data %d",index);
16415 editinfo_dlg[0].dp = caption;
16416 editinfo_dlg[0].dp2 = get_zc_font(font_lfont);
16417
16418 sprintf(ps1,"%d",QMisc.info[index].price[0]);
16419 sprintf(ps2,"%d",QMisc.info[index].price[1]);
16420 sprintf(ps3,"%d",QMisc.info[index].price[2]);
16421 strncpy(infoname,QMisc.info[index].name,32);
16422 infoname[32] = 0;
16423 editinfo_dlg[8].dp = ps1;
16424 editinfo_dlg[10].dp = ps2;
16425 editinfo_dlg[12].dp = ps3;
16426 editinfo_dlg[15].dp = infoname;
16427 str1 = QMisc.info[index].str[0];
16428 str2 = QMisc.info[index].str[1];
16429 str3 = QMisc.info[index].str[2];
16430 editinfo_dlg[9].d1 = MsgStrings[str1].listpos;
16431 editinfo_dlg[11].d1 = MsgStrings[str2].listpos;
16432 editinfo_dlg[13].d1 = MsgStrings[str3].listpos;
16433 ListData msgs_list(msgslist2, &a4fonts[font_lfont_l]);
16434 editinfo_dlg[9].dp =
16435 editinfo_dlg[11].dp =
16436 editinfo_dlg[13].dp = (void *) &msgs_list;
16437
16438 large_dialog(editinfo_dlg);
16439
16440 int32_t ret = do_zqdialog(editinfo_dlg,-1);
16441
16442 if(ret==16)
16443 {
16444 saved=false;
16445 QMisc.info[index].price[0] = vbound(atoi(ps1), 0, 65535);
16446 QMisc.info[index].price[1] = vbound(atoi(ps2), 0, 65535);
16447 QMisc.info[index].price[2] = vbound(atoi(ps3), 0, 65535);
16448 strncpy(QMisc.info[index].name,infoname,32);
16449 str1 = editinfo_dlg[9].d1;
16450 str2 = editinfo_dlg[11].d1;
16451 str3 = editinfo_dlg[13].d1;
16452 QMisc.info[index].str[0] = msg_at_pos(str1);
16453 QMisc.info[index].str[1] = msg_at_pos(str2);
16454 QMisc.info[index].str[2] = msg_at_pos(str3);
16455
16456 //move 0s to the end
16457 word swaptmp;
16458
16459 if(QMisc.info[index].str[0] == 0)
16460 {
16461 //possibly permute the infos
16462 if(QMisc.info[index].str[1] != 0)
16463 {
16464 //swap
16465 swaptmp = QMisc.info[index].str[0];
16466 QMisc.info[index].str[0] = QMisc.info[index].str[1];
16467 QMisc.info[index].str[1] = swaptmp;
16468 swaptmp = QMisc.info[index].price[0];
16469 QMisc.info[index].price[0] = QMisc.info[index].price[1];
16470 QMisc.info[index].price[1] = swaptmp;
16471 }
16472 else if(QMisc.info[index].str[2] != 0)
16473 {
16474 //move info 0 to 1, 1 to 2, and 2 to 0
16475 swaptmp = QMisc.info[index].str[0];
16476 QMisc.info[index].str[0] = QMisc.info[index].str[2];
16477 QMisc.info[index].str[2] = QMisc.info[index].str[1];
16478 QMisc.info[index].str[1] = swaptmp;
16479 swaptmp = QMisc.info[index].price[0];
16480 QMisc.info[index].price[0] = QMisc.info[index].price[2];
16481 QMisc.info[index].price[2] = QMisc.info[index].price[1];
16482 QMisc.info[index].price[1] = swaptmp;
16483 }
16484 }
16485
16486 if(QMisc.info[index].str[1] == 0 && QMisc.info[index].str[2] != 0)
16487 //swap
16488 {
16489 swaptmp = QMisc.info[index].str[1];
16490 QMisc.info[index].str[1] = QMisc.info[index].str[2];
16491 QMisc.info[index].str[2] = swaptmp;
16492 swaptmp = QMisc.info[index].price[1];
16493 QMisc.info[index].price[1] = QMisc.info[index].price[2];
16494 QMisc.info[index].price[2] = swaptmp;
16495 }
16496 }
16497 }
16498
16499 int32_t onInfoTypes()
16500 {
16501 info_list_size = 256;
16502
16503 int32_t index = select_data("Info Types",0,infolist,"Edit","Done",get_zc_font(font_lfont));
16504
16505 while(index!=-1)
16506 {
16507 EditInfoType(index);
16508
16509 index = select_data("Info Types",index,infolist,"Edit","Done",get_zc_font(font_lfont));
16510 }
16511
16512 return D_O_K;
16513 }
16514
16515
16516
16517 //This dialogie is self-contained, and does not use dialogue control numbers in a separate array to generate its fields.
16518 static DIALOG editshop_dlg[] =
16519 {
16520 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
16521 12 { jwin_win_proc, 0, 10, 221, 204, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
16522 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
16523 12 { jwin_text_proc, 24, 60, 48, 8, vc(7), vc(1), 0, 0, 0, 0, (void *) "1st", NULL, NULL },
16524 12 { jwin_text_proc, 24, 106, 48, 8, vc(7), vc(1), 0, 0, 0, 0, (void *) "2nd", NULL, NULL },
16525 12 { jwin_text_proc, 24, 152, 48, 8, vc(7), vc(1), 0, 0, 0, 0, (void *) "3rd", NULL, NULL },
16526 12 { jwin_text_proc, 56, 60, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Price:", NULL, NULL },
16527 12 { jwin_text_proc, 56, 106, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Price:", NULL, NULL },
16528 12 { jwin_text_proc, 56, 152, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Price:", NULL, NULL },
16529 // 8
16530 12 { jwin_edit_proc, 86, 56, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16531 12 { d_nidroplist_proc, 56, 74, 137, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16532 12 { jwin_edit_proc, 86, 102, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16533 12 { d_nidroplist_proc, 56, 120, 137, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16534 12 { jwin_edit_proc, 86, 148, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16535 12 { d_nidroplist_proc, 56, 166, 137, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16536 12 { jwin_text_proc, 24, 42, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Name:", NULL, NULL },
16537 12 { jwin_edit_proc, 56, 38, 137, 16, vc(12), vc(1), 0, 0, 31, 0, NULL, NULL, NULL },
16538
16539 // 16
16540 12 { jwin_button_proc, 40, 188, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
16541 12 { jwin_button_proc, 121, 188, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
16542 //18
16543 12 { jwin_text_proc, 130, 60, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Info:", NULL, NULL },
16544 12 { jwin_text_proc, 130, 106, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Info:", NULL, NULL },
16545 12 { jwin_text_proc, 130, 152, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Info:", NULL, NULL },
16546 // 21
16547 12 { jwin_edit_proc, 155, 56, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16548 12 { jwin_edit_proc, 155, 102, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16549 12 { jwin_edit_proc, 155, 148, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16550
16551 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
16552 };
16553
16554 void EditShopType(int32_t index)
16555 {
16556
16557 build_bii_list(true);
16558 char ps1[6],ps2[6],ps3[6];
16559 char info1[6],info2[6],info3[6];
16560 char shopname[32];
16561 char caption[40];
16562
16563 sprintf(caption,"Shop Data %d",index);
16564 editshop_dlg[0].dp = caption;
16565 editshop_dlg[0].dp2=get_zc_font(font_lfont);
16566
16567 sprintf(ps1,"%d",QMisc.shop[index].price[0]);
16568 sprintf(ps2,"%d",QMisc.shop[index].price[1]);
16569 sprintf(ps3,"%d",QMisc.shop[index].price[2]);
16570
16571 sprintf(info1,"%d",QMisc.shop[index].str[0]);
16572 sprintf(info2,"%d",QMisc.shop[index].str[1]);
16573 sprintf(info3,"%d",QMisc.shop[index].str[2]);
16574
16575 sprintf(shopname,"%s",QMisc.shop[index].name);
16576 editshop_dlg[8].dp = ps1;
16577 editshop_dlg[10].dp = ps2;
16578 editshop_dlg[12].dp = ps3;
16579 editshop_dlg[15].dp = shopname;
16580
16581 editshop_dlg[21].dp = info1;
16582 editshop_dlg[22].dp = info2;
16583 editshop_dlg[23].dp = info3;
16584
16585 ListData item_list(itemlist_num, &a4fonts[font_lfont_l]);
16586
16587 editshop_dlg[9].dp = (void *) &item_list;
16588 editshop_dlg[11].dp = (void *) &item_list;
16589 editshop_dlg[13].dp = (void *) &item_list;
16590
16591 for(int32_t i=0; i<3; ++i)
16592 {
16593 if(QMisc.shop[index].hasitem[i])
16594 {
16595 for(int32_t j=0; j<bii_cnt; j++)
16596 {
16597 if(bii[j].i == QMisc.shop[index].item[i])
16598 {
16599 editshop_dlg[9+(i<<1)].d1 = j;
16600 }
16601 }
16602 }
16603 else
16604 {
16605 editshop_dlg[9+(i<<1)].d1 = -2;
16606 }
16607 }
16608
16609 large_dialog(editshop_dlg);
16610
16611 int32_t ret = do_zqdialog(editshop_dlg,-1);
16612
16613 if(ret==16)
16614 {
16615 saved=false;
16616 QMisc.shop[index].price[0] = vbound(atoi(ps1), 0, 65535);
16617 QMisc.shop[index].price[1] = vbound(atoi(ps2), 0, 65535);
16618 QMisc.shop[index].price[2] = vbound(atoi(ps3), 0, 65535);
16619
16620 QMisc.shop[index].str[0] = vbound(atoi(info1), 0, 65535);
16621 QMisc.shop[index].str[1] = vbound(atoi(info2), 0, 65535);
16622 QMisc.shop[index].str[2] = vbound(atoi(info3), 0, 65535);
16623
16624 snprintf(QMisc.shop[index].name, 32, "%s",shopname);
16625
16626 for(int32_t i=0; i<3; ++i)
16627 {
16628 if(bii[editshop_dlg[9+(i<<1)].d1].i == -2)
16629 {
16630 QMisc.shop[index].hasitem[i] = 0;
16631 QMisc.shop[index].item[i] = 0;
16632 QMisc.shop[index].price[i] = 0;
16633 }
16634 else
16635 {
16636 QMisc.shop[index].hasitem[i] = 1;
16637 QMisc.shop[index].item[i] = bii[editshop_dlg[9+(i<<1)].d1].i;
16638 }
16639 }
16640
16641 //filter all the 0 items to the end (yeah, bubble sort; sue me)
16642 word swaptmp;
16643
16644 for(int32_t j=0; j<3-1; j++)
16645 {
16646 for(int32_t k=0; k<2-j; k++)
16647 {
16648 if(QMisc.shop[index].hasitem[k]==0)
16649 {
16650 swaptmp = QMisc.shop[index].item[k];
16651 QMisc.shop[index].item[k] = QMisc.shop[index].item[k+1];
16652 QMisc.shop[index].item[k+1] = swaptmp;
16653 swaptmp = QMisc.shop[index].price[k];
16654 QMisc.shop[index].price[k] = QMisc.shop[index].price[k+1];
16655 QMisc.shop[index].price[k+1] = swaptmp;
16656 swaptmp = QMisc.shop[index].hasitem[k];
16657 QMisc.shop[index].hasitem[k] = QMisc.shop[index].item[k+1];
16658 QMisc.shop[index].hasitem[k+1] = swaptmp;
16659 }
16660 }
16661 }
16662 }
16663 }
16664
16665 int32_t onShopTypes()
16666 {
16667 shop_list_size = 256;
16668
16669 int32_t index = select_data("Shop Types",0,shoplist,"Edit","Done",get_zc_font(font_lfont));
16670
16671 while(index!=-1)
16672 {
16673 EditShopType(index);
16674 index = select_data("Shop Types",index,shoplist,"Edit","Done",get_zc_font(font_lfont));
16675 }
16676
16677 return D_O_K;
16678 }
16679
16680 void call_bottle_dlg(int32_t index);
16681 int32_t onBottleTypes()
16682 {
16683 bottle_list_size = 64;
16684 int32_t index = 0;
16685
16686 while(index > -1)
16687 {
16688 index = select_data("Bottle Types", index, bottlelist, "Edit", "Done", get_zc_font(font_lfont));
16689 if(index > -1)
16690 call_bottle_dlg(index);
16691 }
16692
16693 return D_O_K;
16694 }
16695
16696 void call_bottleshop_dlg(int32_t index);
16697 int32_t onBottleShopTypes()
16698 {
16699 bottleshop_list_size = 256;
16700 int32_t index = 0;
16701
16702 while(index > -1)
16703 {
16704 index = select_data("Bottle Shop Types", index, bottleshoplist, "Edit", "Done", get_zc_font(font_lfont));
16705 if(index > -1)
16706 call_bottleshop_dlg(index);
16707 }
16708
16709 return D_O_K;
16710 }
16711
16712
16713 static char item_drop_set_str_buf[70];
16714 int32_t item_drop_set_list_size=MAXITEMDROPSETS;
16715
16716 const char *itemdropsetlist(int32_t index, int32_t *list_size)
16717 {
16718 if(index>=0)
16719 {
16720 bound(index,0,item_drop_set_list_size-1);
16721 sprintf(item_drop_set_str_buf,"%3d: %s",index,item_drop_sets[index].name);
16722 return item_drop_set_str_buf;
16723 }
16724
16725 *list_size=item_drop_set_list_size;
16726 return NULL;
16727 }
16728
16729 int32_t d_itemdropedit_proc(int32_t msg,DIALOG *d,int32_t c);
16730
16731 static int32_t edititemdropset_1_list[] =
16732 {
16733 // dialog control number
16734 10, 11, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,24,25,26,27,28, -1
16735 };
16736
16737 static int32_t edititemdropset_2_list[] =
16738 {
16739 // dialog control number
16740 12, 13, 29, 30, 31, 32, 33,34,35,36,37,38,39,40,41,42,43, -1
16741 };
16742
16743 static TABPANEL edititemdropset_tabs[] =
16744 {
16745 // (text)
16746 { (char *)" Page 1 ", D_SELECTED, edititemdropset_1_list, 0, NULL },
16747 { (char *)" Page 2 ", 0, edititemdropset_2_list, 0, NULL },
16748 { NULL, 0, NULL, 0, NULL }
16749 };
16750
16751 static DIALOG edititemdropset_dlg[] =
16752 {
16753 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
16754 12 { jwin_win_proc, 0, 0, 320, 240, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
16755 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
16756
16757 // 2
16758 12 { jwin_button_proc, 89, 213, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
16759 12 { jwin_button_proc, 169, 213, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
16760
16761 // 4
16762 12 { jwin_text_proc, 9, 29, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Name:", NULL, NULL },
16763 12 { jwin_edit_proc, 39, 25, 275, 16, vc(12), vc(1), 0, 0, 32, 0, NULL, NULL, NULL },
16764 12 { jwin_text_proc, 9, 47, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Nothing Chance:", NULL, NULL },
16765 12 { d_itemdropedit_proc, 84, 43, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16766
16767 12 { jwin_tab_proc, 4, 65, 312, 143, vc(0), vc(15), 0, 0, 0, 0, (void *) edititemdropset_tabs, NULL, (void *)edititemdropset_dlg },
16768 12 { jwin_text_proc, 114, 43+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16769 // 10
16770 12 { jwin_text_proc, 10, 87, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Chance:", NULL, NULL },
16771 12 { jwin_text_proc, 56, 87, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Item:", NULL, NULL },
16772 12 { jwin_text_proc, 10, 87, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Chance:", NULL, NULL },
16773 12 { jwin_text_proc, 56, 87, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Item:", NULL, NULL },
16774
16775 // 14
16776 12 { d_itemdropedit_proc, 9, 96, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16777 12 { d_idroplist_proc, 55, 96, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16778 12 { jwin_text_proc, 37, 96+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16779 12 { d_itemdropedit_proc, 9, 118, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16780 12 { d_idroplist_proc, 55, 118, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16781 12 { jwin_text_proc, 37, 118+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16782 12 { d_itemdropedit_proc, 9, 140, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16783 12 { d_idroplist_proc, 55, 140, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16784 12 { jwin_text_proc, 37, 140+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16785 12 { d_itemdropedit_proc, 9, 162, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16786 12 { d_idroplist_proc, 55, 162, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16787 12 { jwin_text_proc, 37, 162+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16788 12 { d_itemdropedit_proc, 9, 184, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16789 12 { d_idroplist_proc, 55, 184, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16790 12 { jwin_text_proc, 37, 184+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16791 // 29
16792 12 { d_itemdropedit_proc, 9, 96, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16793 12 { d_idroplist_proc, 55, 96, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16794 12 { jwin_text_proc, 37, 96+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16795 12 { d_itemdropedit_proc, 9, 118, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16796 12 { d_idroplist_proc, 55, 118, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16797 12 { jwin_text_proc, 37, 118+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16798 12 { d_itemdropedit_proc, 9, 140, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16799 12 { d_idroplist_proc, 55, 140, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16800 12 { jwin_text_proc, 37, 140+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16801 12 { d_itemdropedit_proc, 9, 162, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16802 12 { d_idroplist_proc, 55, 162, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16803 12 { jwin_text_proc, 37, 162+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16804 12 { d_itemdropedit_proc, 9, 184, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16805 12 { d_idroplist_proc, 55, 184, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16806 12 { jwin_text_proc, 39, 184+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16807 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
16808 };
16809
16810 int32_t d_itemdropedit_proc(int32_t msg,DIALOG *d,int32_t c)
16811 {
16812 int32_t ret = jwin_edit_proc(msg,d,c);
16813
16814 if(msg==MSG_DRAW)
16815 {
16816 int32_t t = atoi((char*)edititemdropset_dlg[7].dp);
16817
16818 for(int32_t i=0; i<10; ++i)
16819 {
16820 t += atoi((char*)edititemdropset_dlg[14+(i*3)].dp);
16821 }
16822
16823 {
16824 int32_t t2 = (int32_t)(100*atoi((char*)edititemdropset_dlg[7].dp) / zc_max(t,1));
16825 sprintf((char*)edititemdropset_dlg[9].dp,"%d%%%s",t2, t2 <= 11 ? " ":"");
16826 object_message(&edititemdropset_dlg[9],MSG_DRAW,c);
16827 }
16828
16829 for(int32_t i=0; i<10; ++i)
16830 {
16831 int32_t t2 = (int32_t)(100*atoi((char*)edititemdropset_dlg[14+(i*3)].dp) / zc_max(t,1));
16832 sprintf((char*)edititemdropset_dlg[16+(i*3)].dp,"%d%%%s",t2, t2 <= 11 ? " ":"");
16833 object_message(&edititemdropset_dlg[16+(i*3)],MSG_DRAW,c);
16834 }
16835
16836 }
16837
16838 return ret;
16839 }
16840
16841 void EditItemDropSet(int32_t index)
16842 {
16843 build_bii_list(true);
16844 char chance[11][10];
16845 char itemdropsetname[64];
16846 char caption[40];
16847 char percent_str[11][5];
16848
16849 sprintf(caption,"Item Drop Set Data %d",index);
16850 edititemdropset_dlg[0].dp = caption;
16851 edititemdropset_dlg[0].dp2=get_zc_font(font_lfont);
16852
16853 sprintf(itemdropsetname,"%s",item_drop_sets[index].name);
16854 edititemdropset_dlg[5].dp = itemdropsetname;
16855
16856 sprintf(chance[0],"%d",item_drop_sets[index].chance[0]);
16857 edititemdropset_dlg[7].dp = chance[0];
16858
16859 ListData item_list(itemlist_num, &a4fonts[font_lfont_l]);
16860 sprintf(percent_str[0]," ");
16861 edititemdropset_dlg[9].dp = percent_str[0];
16862
16863 for(int32_t i=0; i<10; ++i)
16864 {
16865 sprintf(chance[i+1],"%d",item_drop_sets[index].chance[i+1]);
16866 edititemdropset_dlg[14+(i*3)].dp = chance[i+1];
16867 edititemdropset_dlg[15+(i*3)].dp = (void *) &item_list;
16868 sprintf(percent_str[i+1]," ");
16869 edititemdropset_dlg[16+(i*3)].dp = percent_str[i+1];
16870
16871 if(item_drop_sets[index].chance[i+1]==0)
16872 {
16873 edititemdropset_dlg[15+(i*3)].d1 = -2;
16874 }
16875 else
16876 {
16877 for(int32_t j=0; j<bii_cnt; j++)
16878 {
16879 if(bii[j].i == item_drop_sets[index].item[i])
16880 {
16881 edititemdropset_dlg[15+(i*3)].d1 = j;
16882 }
16883 }
16884 }
16885 }
16886
16887 large_dialog(edititemdropset_dlg);
16888
16889 int32_t ret = do_zqdialog(edititemdropset_dlg,-1);
16890
16891 if(ret==2)
16892 {
16893 saved=false;
16894
16895 sprintf(item_drop_sets[index].name,"%s",itemdropsetname);
16896
16897 item_drop_sets[index].chance[0]=atoi(chance[0]);
16898
16899 for(int32_t i=0; i<10; ++i)
16900 {
16901 item_drop_sets[index].chance[i+1]=atoi(chance[i+1]);
16902
16903 if(bii[edititemdropset_dlg[15+(i*3)].d1].i == -2)
16904 {
16905 item_drop_sets[index].chance[i+1]=0;
16906 }
16907 else
16908 {
16909 item_drop_sets[index].item[i] = bii[edititemdropset_dlg[15+(i*3)].d1].i;
16910 }
16911
16912 if(item_drop_sets[index].chance[i+1]==0)
16913 {
16914 item_drop_sets[index].item[i] = 0;
16915 }
16916 }
16917 }
16918 }
16919
16920 9 int32_t count_item_drop_sets()
16921 {
16922 9 int32_t count=0;
16923 9 bool found=false;
16924
16925
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2195 times.
2195 for(count=255; (count>0); --count)
16926 {
16927
2/2
✓ Branch 0 taken 2186 times.
✓ Branch 1 taken 24056 times.
26242 for(int32_t i=0; (i<11); ++i)
16928 {
16929
2/2
✓ Branch 0 taken 24047 times.
✓ Branch 1 taken 9 times.
24056 if(item_drop_sets[count].chance[i]!=0)
16930 {
16931 9 found=true;
16932 9 break;
16933 }
16934 24047 }
16935
16936
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 2186 times.
2195 if(found)
16937 {
16938 9 break;
16939 }
16940 2186 }
16941
16942 9 return count+1;
16943 }
16944
16945 int32_t onItemDropSets()
16946 {
16947 item_drop_set_list_size = MAXITEMDROPSETS;
16948
16949 int32_t index = select_data("Item Drop Sets",0,itemdropsetlist,"Edit","Done",get_zc_font(font_lfont));
16950
16951 while(index!=-1)
16952 {
16953 EditItemDropSet(index);
16954 index = select_data("Item Drop Sets",index,itemdropsetlist,"Edit","Done",get_zc_font(font_lfont));
16955 }
16956
16957 return D_O_K;
16958 }
16959
16960 int32_t curr_ring = 0;
16961
16962 void EditWarpRingScr(int32_t ring,int32_t index)
16963 {
16964 char caption[40],buf[10];
16965 restore_mouse();
16966
16967 sprintf(caption,"Ring %d Warp %d",ring,index+1);
16968 warpring_warp_dlg[0].dp = (void *)caption;
16969 warpring_warp_dlg[0].dp2=get_zc_font(font_lfont);
16970
16971 sprintf(buf,"%02X",QMisc.warp[ring].scr[index]);
16972 warpring_warp_dlg[3].d1 = QMisc.warp[ring].dmap[index];
16973 warpring_warp_dlg[4].dp = buf;
16974 warpring_warp_dlg[8].dp = buf;
16975 warpring_warp_dlg[8].dp3 = &warpring_warp_dlg[3].d1;
16976
16977 vector<DIALOG*> dlgs;
16978 dlgs.push_back(&warpring_warp_dlg[3]);
16979 dlgs.push_back(&warpring_warp_dlg[4]);
16980 warpring_warp_dlg[8].dp2 = &dlgs;
16981
16982 dmap_list_size=MAXDMAPS;
16983 dmap_list_zero=true;
16984
16985 large_dialog(warpring_warp_dlg);
16986
16987 int32_t ret=do_zqdialog(warpring_warp_dlg,-1);
16988
16989 if(ret==5 || ret==6)
16990 {
16991 saved=false;
16992 QMisc.warp[ring].dmap[index] = warpring_warp_dlg[3].d1;
16993 QMisc.warp[ring].scr[index] = zc_xtoi(buf);
16994 }
16995
16996 if(ret==6)
16997 {
16998 Map.dowarp2(ring,index);
16999 refresh(rALL);
17000 }
17001 }
17002
17003 int32_t d_warplist_proc(int32_t msg,DIALOG *d,int32_t c)
17004 {
17005 if(msg==MSG_DRAW)
17006 {
17007 int32_t *xy = (int32_t*)(d->dp3);
17008 int32_t ring = curr_ring;
17009 int32_t dmap = QMisc.warp[ring].dmap[d->d1];
17010 float temp_scale = 1.5;
17011
17012 drawdmap(dmap);
17013
17014 if(xy[0]||xy[1])
17015 {
17016 int32_t x = d->x+int32_t((xy[0]-2)*temp_scale);
17017 int32_t y = d->y+int32_t((xy[1]-2)*temp_scale);
17018 int32_t w = 84;
17019 int32_t h = 52;
17020 jwin_draw_frame(screen,x,y,w,h,FR_DEEP);
17021 drawdmap_screen(x+2,y+2,w-4,h-4,dmap);
17022 }
17023
17024 if(xy[2]||xy[3])
17025 {
17026 textprintf_ex(screen,font,d->x+int32_t(xy[2]*temp_scale),d->y+int32_t(xy[3]*temp_scale),jwin_pal[jcBOXFG],jwin_pal[jcBOX],"Map: %d ",DMaps[dmap].map+1);
17027 }
17028
17029 if(xy[4]||xy[5])
17030 {
17031 textprintf_ex(screen,font,d->x+int32_t(xy[4]*temp_scale),d->y+int32_t(xy[5]*temp_scale),jwin_pal[jcBOXFG],jwin_pal[jcBOX],"Level:%2d ",DMaps[dmap].level);
17032 }
17033
17034 if(xy[6]||xy[7])
17035 {
17036 textprintf_ex(screen,font,d->x+int32_t(xy[6]*temp_scale),d->y+int32_t(xy[7]*temp_scale),jwin_pal[jcBOXFG],jwin_pal[jcBOX],"Scr: 0x%02X ",QMisc.warp[ring].scr[d->d1]);
17037 }
17038 }
17039
17040 return jwin_list_proc(msg,d,c);
17041 }
17042
17043 int32_t d_wclist_proc(int32_t msg,DIALOG *d,int32_t c)
17044 {
17045 int32_t d1 = d->d1;
17046 int32_t ret = jwin_droplist_proc(msg,d,c);
17047 QMisc.warp[curr_ring].size=d->d1+3;
17048
17049 if(d->d1 != d1)
17050 return D_CLOSE;
17051
17052 return ret;
17053 }
17054
17055 const char *wclist(int32_t index, int32_t *list_size)
17056 {
17057 static char buf[2];
17058
17059 if(index>=0)
17060 {
17061 if(index>6)
17062 index=6;
17063
17064 sprintf(buf,"%d",index+3);
17065 return buf;
17066 }
17067
17068 *list_size=7;
17069 return NULL;
17070 }
17071
17072 //int32_t warpringdmapxy[8] = {160,116,160,90,160,102,160,154};
17073 int32_t warpringdmapxy[8] = {80,26,80,0,80,12,80,78};
17074
17075 12 static ListData number_list(numberlist, &font);
17076 12 static ListData wc_list(wclist, &font);
17077
17078 static DIALOG warpring_dlg[] =
17079 {
17080 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
17081 12 { jwin_win_proc, 0, 0, 193, 166, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
17082 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
17083 12 { jwin_text_proc, 16, 33, 48, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Count:", NULL, NULL },
17084 12 { d_wclist_proc, 72, 29, 48, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 1, 0, (void *) &wc_list, NULL, NULL },
17085 // 4
17086 12 { d_warplist_proc, 16, 50, 65, 71, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, D_EXIT, 0, 0, (void *) &number_list, NULL, warpringdmapxy },
17087 12 { jwin_button_proc, 26, 140, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Edit", NULL, NULL },
17088 12 { jwin_button_proc, 106, 140, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Done", NULL, NULL },
17089 12 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F1, 0, (void *) onHelp, NULL, NULL },
17090 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
17091 };
17092
17093 int32_t select_warp()
17094 {
17095 QMisc.warp[curr_ring].size = vbound(QMisc.warp[curr_ring].size,3,9);
17096 number_list_zero = false;
17097
17098 int32_t ret=4;
17099
17100 large_dialog(warpring_dlg);
17101
17102 do
17103 {
17104 number_list_size = QMisc.warp[curr_ring].size;
17105 warpring_dlg[3].d1 = QMisc.warp[curr_ring].size-3;
17106 ret = do_zqdialog(warpring_dlg,ret);
17107 }
17108 while(ret==3);
17109
17110 if(ret==6 || ret==0)
17111 {
17112 return -1;
17113 }
17114
17115 return warpring_dlg[4].d1;
17116 }
17117
17118 void EditWarpRing(int32_t ring)
17119 {
17120 char buf[40];
17121 sprintf(buf,"Ring %d Warps",ring);
17122 warpring_dlg[0].dp = buf;
17123 warpring_dlg[0].dp2 = get_zc_font(font_lfont);
17124 curr_ring = ring;
17125
17126 int32_t index = select_warp();
17127
17128 while(index!=-1)
17129 {
17130 EditWarpRingScr(ring,index);
17131 index = select_warp();
17132 }
17133 }
17134
17135 int32_t onWarpRings()
17136 {
17137 number_list_size = 9;
17138 number_list_zero = true;
17139
17140 int32_t index = select_data("Warp Rings",0,numberlist,"Edit","Done",get_zc_font(font_lfont));
17141
17142 while(index!=-1)
17143 {
17144 EditWarpRing(index);
17145 number_list_size = 9;
17146 number_list_zero = true;
17147 index = select_data("Warp Rings",index,numberlist,"Edit","Done",get_zc_font(font_lfont));
17148 }
17149
17150 return D_O_K;
17151 }
17152
17153 const char *enemy_viewer(int32_t index, int32_t *list_size)
17154 {
17155 if(index<0)
17156 {
17157 *list_size=10;
17158
17159 return NULL;
17160 }
17161
17162 int32_t guy=Map.CurrScr()->enemy[index];
17163
17164 if (guy == 0) return "(None)";
17165 return guy>=eSTART ? guy_string[guy] : (char *) "(Guy - Do Not Use!)";
17166 }
17167
17168 enemy_struct bie[eMAXGUYS];
17169 enemy_struct ce[100];
17170 int32_t enemy_type=0,bie_cnt=-1,ce_cnt;
17171
17172 enemy_struct big[zqMAXGUYS];
17173 enemy_struct cg[100];
17174 int32_t guy_type=0,big_cnt=-1,cg_cnt;
17175
17176 //Uses old_max_guys[] in zq_misc.cpp to define what are visible if bool hide is set true. -Z
17177 void build_bie_list(bool hide)
17178 {
17179 bie[0].s = (char *)"(None)";
17180 bie[0].i = 0;
17181 bie_cnt=1;
17182
17183 for(int32_t i=1; i<eMAXGUYS; i++)
17184 {
17185 if (i < eSTART) continue; // ignore guys - enemies only!
17186
17187 if(i >= OLDMAXGUYS || old_guy_string[i][strlen(old_guy_string[i])-1]!=' ' || !hide)
17188 {
17189 bie[bie_cnt].s = (char *)guy_string[i];
17190 bie[bie_cnt].i = i;
17191 ++bie_cnt;
17192 }
17193 }
17194
17195 for(int32_t i=1; i<bie_cnt-1; i++) //Start at 1 so '(None)' isn't alphabetized!
17196 {
17197 for(int32_t j=i+1; j<bie_cnt; j++)
17198 {
17199 if(strcmp(bie[i].s,bie[j].s)>0)
17200 {
17201 zc_swap(bie[i],bie[j]);
17202 }
17203 }
17204 }
17205 }
17206
17207 int32_t efrontfacingtile(int32_t id)
17208 {
17209 int32_t anim = get_qr(qr_NEWENEMYTILES)?guysbuf[id].e_anim:guysbuf[id].anim;
17210 int32_t usetile = 0;
17211
17212 switch(anim)
17213 {
17214
17215 case aNONE: break;
17216 case aAQUA:
17217 if(!(get_qr(qr_NEWENEMYTILES) && guysbuf[id].attributes[0]))
17218 break;
17219
17220 case aWALLM:
17221 case aGHOMA:
17222 usetile=1;
17223 break;
17224
17225 //Fallthrough
17226 case a2FRM4DIR:
17227 case aWALK:
17228 usetile=2;
17229 break;
17230
17231 case aLEV:
17232 case a3FRM4DIR:
17233 usetile=3;
17234 break;
17235
17236 case aLANM:
17237 usetile = !(get_qr(qr_NEWENEMYTILES))?0:4;
17238 break;
17239
17240 case aNEWDONGO:
17241 case a4FRM8EYE:
17242 case aNEWWIZZ:
17243 case aARMOS4:
17244 case aNEWTEK:
17245 case aNEWWALLM:
17246 case a4FRM4DIRF:
17247 case a4FRM4DIR:
17248 case a4FRM8DIRF:
17249 case a4FRMPOS8DIR:
17250 case a4FRMPOS8DIRF:
17251 case a4FRMPOS4DIR:
17252 case a4FRMPOS4DIRF:
17253 usetile=4;
17254 break;
17255
17256 case aDONGO:
17257 usetile=6;
17258 break;
17259
17260 case aDONGOBS:
17261 usetile=24;
17262 break;
17263
17264 case aNEWLEV:
17265 usetile=40;
17266 break;
17267
17268 case aNEWZORA:
17269 if(guysbuf[id].type==eeZORA)
17270 usetile=44;
17271
17272 break;
17273
17274 case aGLEEOK:
17275 if(!get_qr(qr_NEWENEMYTILES))
17276 usetile = (guysbuf[id].s_tile - guysbuf[id].tile)+1;
17277 else
17278 usetile = (guysbuf[id].attributes[7]);
17279
17280 break;
17281 }
17282
17283 return zc_max(get_qr(qr_NEWENEMYTILES) ? -guysbuf[id].e_tile
17284 : -guysbuf[id].tile, usetile);
17285 }
17286
17287 int32_t onEnemies()
17288 {
17289 call_screenenemies_dialog();
17290 refresh(rALL);
17291 return D_O_K;
17292 }
17293
17294 char author[65],title[65],password[32];
17295
17296 int32_t d_showedit_proc(int32_t msg,DIALOG *d,int32_t c)
17297 {
17298 int32_t ret = jwin_edit_proc(msg,d,c);
17299
17300 if(msg==MSG_DRAW)
17301 {
17302 (d+1)->proc(MSG_DRAW,d+1,0);
17303 }
17304
17305 return ret;
17306 }
17307
17308 int32_t onHeader()
17309 {
17310 call_header_dlg();
17311 return D_O_K;
17312 }
17313
17314 void call_cheats_dlg();
17315 int32_t onCheats()
17316 {
17317 call_cheats_dlg();
17318 return D_O_K;
17319 }
17320
17321 bool do_x_button(BITMAP *dest, int32_t x, int32_t y)
17322 {
17323 bool over=false;
17324
17325 while(gui_mouse_b())
17326 {
17327 custom_vsync();
17328
17329 if(isinRect(gui_mouse_x(),gui_mouse_y(),x,y,x+15,y+13))
17330 {
17331 if(!over)
17332 {
17333 draw_x_button(dest, x, y, D_SELECTED);
17334 over=true;
17335 }
17336 }
17337 else
17338 {
17339 if(over)
17340 {
17341 draw_x_button(dest, x, y, 0);
17342 over=false;
17343 }
17344 }
17345 }
17346
17347 return over;
17348 }
17349
17350 bool do_question_button(BITMAP *dest, int32_t x, int32_t y)
17351 {
17352 bool over=false;
17353
17354 while(gui_mouse_b())
17355 {
17356 custom_vsync();
17357
17358 if(isinRect(gui_mouse_x(),gui_mouse_y(),x,y,x+15,y+13))
17359 {
17360 if(!over)
17361 {
17362 draw_question_button(dest, x, y, D_SELECTED);
17363 over=true;
17364 }
17365 }
17366 else
17367 {
17368 if(over)
17369 {
17370 draw_question_button(dest, x, y, 0);
17371 over=false;
17372 }
17373 }
17374 }
17375
17376 return over;
17377 }
17378
17379
17380 int32_t d_dummy_proc(int32_t,DIALOG *,int32_t)
17381 {
17382 return D_O_K;
17383 }
17384
17385 int32_t d_maptile_proc(int32_t msg, DIALOG *d, int32_t)
17386 {
17387 switch(msg)
17388 {
17389 case MSG_CLICK:
17390 if(select_tile(d->d1,d->d2,1,d->fg,true, 0, true))
17391 return D_REDRAW;
17392
17393 case MSG_DRAW:
17394 {
17395 int32_t dw = d->w;
17396 int32_t dh = d->h;
17397
17398 if(d->dp2==(void*)1)
17399 {
17400 dw /= 2;
17401 dh /= 2;
17402 }
17403
17404 BITMAP *buf = create_bitmap_ex(8,dw,dh);
17405
17406 if(buf)
17407 {
17408 clear_bitmap(buf);
17409
17410 for(int32_t y=0; y<dh; y+=16)
17411 for(int32_t x=0; x<dw; x+=16)
17412 {
17413 if(d->d1)
17414 puttile16(buf,d->d1+(y>>4)*20+(x>>4),x,y,d->fg,0);
17415 }
17416
17417 if(d->dp2==(void*)1)
17418 stretch_blit(buf,screen,0,0,dw,dh,d->x-1,d->y-1,dw*2,dh*2);
17419 else
17420 blit(buf,screen,0,0,d->x,d->y,dw,dh);
17421
17422 destroy_bitmap(buf);
17423 }
17424 }
17425 }
17426
17427 return D_O_K;
17428 }
17429
17430 static int32_t last_combo=0;
17431 static int32_t last_cset=0;
17432
3/4
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 98292 times.
✓ Branch 3 taken 12 times.
98304 static combo_alias temp_aliases[MAXCOMBOALIASES];
17433
17434 static char comboa_str_buf[32];
17435
17436 int32_t d_comboalist_proc(int32_t msg,DIALOG *d,int32_t c)
17437 {
17438 int32_t d1 = d->d1;
17439 int32_t ret = jwin_droplist_proc(msg,d,c);
17440 comboa_cnt = d->d1;
17441
17442 if(d1!=d->d1)
17443 {
17444 set_comboaradio(temp_aliases[comboa_cnt].layermask);
17445 return D_REDRAW;
17446 }
17447
17448 return ret;
17449 }
17450
17451 const char *comboalist(int32_t index, int32_t *list_size)
17452 {
17453 if(index>=0)
17454 {
17455 bound(index,0,MAXCOMBOALIASES-1);
17456 sprintf(comboa_str_buf,"%d",index);
17457 return comboa_str_buf;
17458 }
17459
17460 *list_size=MAXCOMBOALIASES;
17461 return NULL;
17462 }
17463
17464 extern int32_t scheme[jcMAX];
17465
17466 int32_t d_comboa_proc(int32_t msg,DIALOG *d,int32_t c)
17467 {
17468 //these are here to bypass compiler warnings about unused arguments
17469 c=c;
17470
17471 combo_alias *combo;
17472 combo = &temp_aliases[comboa_cnt];
17473 int32_t position;
17474 int32_t cur_layer, temp_layer;
17475 int32_t lay_count=0;
17476 int32_t size = 2;
17477
17478 int32_t cx1=(gui_mouse_x()-d->x-(120-(combo->width*8)));
17479 int32_t cy1=(gui_mouse_y()-d->y-(80-(combo->height*8)));
17480 int32_t cx=cx1/(16*size);
17481 int32_t cy=cy1/(16*size);
17482
17483 int32_t co,cs;
17484
17485
17486 switch(msg)
17487 {
17488 case MSG_CLICK:
17489 if((cx>combo->width)||(cx1<0))
17490 return D_O_K;
17491
17492 if((cy>combo->height)||(cy1<0))
17493 return D_O_K;
17494
17495 for(int32_t j=0; j<layer_cnt; j++)
17496 {
17497 if(combo->layermask&(1<<j))
17498 lay_count++;
17499 }
17500
17501 position=(lay_count)*(combo->width+1)*(combo->height+1);
17502 position+=(cy*(combo->width+1))+cx;
17503
17504 if(key[KEY_LSHIFT]||key[KEY_RSHIFT])
17505 {
17506 combo->combos[position] = 0;
17507 combo->csets[position] = 0;
17508
17509 while(gui_mouse_b())
17510 {
17511 /* do nothing */
17512 rest(1);
17513 }
17514
17515 return D_REDRAW;
17516 }
17517
17518 co=combo->combos[position];
17519 cs=combo->csets[position];
17520
17521 if((co==0)||(key[KEY_ZC_LCONTROL]))
17522 {
17523 co=last_combo;
17524 cs=last_cset;
17525 }
17526
17527 if((select_combo_2(co,cs)))
17528 {
17529 last_combo = co;
17530 last_cset = cs;
17531
17532 combo->combos[position]=co;
17533 combo->csets[position]=cs;
17534 }
17535
17536 return D_REDRAW;
17537 break;
17538
17539 case MSG_DRAW:
17540 BITMAP *buf = create_bitmap_ex(8,d->w,d->h);
17541
17542 if(buf)
17543 {
17544 clear_bitmap(buf);
17545
17546 for(int32_t z=0; z<=comboa_lmasktotal(combo->layermask); z++)
17547 {
17548 int32_t k=0;
17549 cur_layer=0;
17550 temp_layer=combo->layermask;
17551
17552 while((temp_layer!=0)&&(k<z))
17553 {
17554 if(temp_layer&1)
17555 {
17556 k++;
17557 }
17558
17559 cur_layer++;
17560 temp_layer = temp_layer>>1;
17561 }
17562
17563 for(int32_t y=0; (y<d->h)&&((y/16)<=combo->height); y+=16)
17564 {
17565 for(int32_t x=0; (x<d->w)&&((x/16)<=combo->width); x+=16)
17566 {
17567 int32_t cpos = (z*(combo->width+1)*(combo->height+1))+(((y/16)*(combo->width+1))+(x/16));
17568
17569 if(combo->combos[cpos])
17570 {
17571 if(!((d-1)->flags&D_SELECTED)||(cur_layer==layer_cnt))
17572 {
17573 if(z==0)
17574 {
17575 puttile16(buf,combobuf[combo->combos[cpos]].tile,x,y,combo->csets[cpos],combobuf[combo->combos[cpos]].flip);
17576 }
17577 else
17578 {
17579 overtile16(buf,combobuf[combo->combos[cpos]].tile,x,y,combo->csets[cpos],combobuf[combo->combos[cpos]].flip);
17580 }
17581 }
17582 }
17583 }
17584 }
17585 }
17586
17587 rectfill(screen, d->x-2,d->y-2,d->x+256+2,d->y+176+2,jwin_pal[jcBOX]);
17588 int32_t dx = 120-(combo->width*8)+d->x;
17589 int32_t dy = 80-(combo->height*8)+d->y;
17590 stretch_blit(buf,screen,0,0,(combo->width+1)*16,(combo->height+1)*16,dx,dy,(combo->width+1)*16*size,(combo->height+1)*16*size);
17591 //blit(buf,screen,0,0,120-(combo->width*8)+d->x,80-(combo->height*8)+d->y,(combo->width+1)*16,(combo->height+1)*16);
17592 (d-11)->w = (combo->width+1)*16*size+2;
17593 (d-11)->h = (combo->height+1)*16*size+2;
17594 (d-11)->x = 120-(combo->width*8)+4*size+2+(d-14)->x;
17595 (d-11)->y = 80-(combo->height*8)+25*size+2+(d-14)->y;
17596 object_message((d-11),MSG_DRAW,0);
17597
17598 destroy_bitmap(buf);
17599 }
17600
17601 break;
17602 }
17603
17604 return D_O_K;
17605 }
17606
17607 void draw_combo_alias_thumbnail(BITMAP *dest, combo_alias const* combo, int32_t x, int32_t y, int32_t size)
17608 {
17609 if(!combo->combo)
17610 {
17611 int32_t cur_layer, temp_layer;
17612
17613 int32_t cw=combo->width+1;
17614 int32_t ch=combo->height+1;
17615 int32_t dw=cw<<4;
17616 int32_t dh=ch<<4;
17617 int32_t sw=16, sh=16, sx=0, sy=0;
17618
17619 if(cw<ch)
17620 {
17621 sw=((cw<<4)/ch);
17622 sx=((16-sw)>>1);
17623 }
17624 else
17625 {
17626 sh=((ch<<4)/cw);
17627 sy=((16-sh)>>1);
17628 }
17629
17630 BITMAP *buf = create_bitmap_ex(8,dw,dh);
17631 BITMAP *buf2 = create_bitmap_ex(8, 16*size, 16*size);
17632 clear_bitmap(buf);
17633 clear_bitmap(buf2);
17634
17635 if(buf&&(combo->width>0||combo->height>0||combo->combos[0]>0))
17636 {
17637 clear_bitmap(buf);
17638
17639 for(int32_t z=0; z<=comboa_lmasktotal(combo->layermask); z++)
17640 {
17641 int32_t k=0;
17642 cur_layer=0;
17643 temp_layer=combo->layermask;
17644
17645 while((temp_layer!=0)&&(k<z))
17646 {
17647 if(temp_layer&1)
17648 {
17649 k++;
17650 }
17651
17652 cur_layer++;
17653 temp_layer = temp_layer>>1;
17654 }
17655
17656 for(int32_t y2=0; (y2<dh)&&((y2>>4)<=combo->height); y2+=16)
17657 {
17658 for(int32_t x2=0; (x2<dw)&&((x2>>4)<=combo->width); x2+=16)
17659 {
17660 int32_t cpos = (z*(combo->width+1)*(combo->height+1))+(((y2/16)*(combo->width+1))+(x2/16));
17661
17662 if(combo->combos[cpos])
17663 {
17664 if(z==0)
17665 {
17666 puttile16(buf,combobuf[combo->combos[cpos]].tile,x2,y2,combo->csets[cpos],combobuf[combo->combos[cpos]].flip);
17667 }
17668 else
17669 {
17670 overtile16(buf,combobuf[combo->combos[cpos]].tile,x2,y2,combo->csets[cpos],combobuf[combo->combos[cpos]].flip);
17671 }
17672 }
17673 }
17674 }
17675 }
17676
17677 stretch_blit(buf, buf2, 0, 0, (cw*16), (ch*16), sx*size, sy*size, sw*size, sh*size);
17678 blit(buf2, dest, 0, 0, x, y, 16*size, 16*size);
17679 }
17680 else
17681 {
17682 rectfill(dest,x,y,x+16*size-1,y+16*size-1,0);
17683 rectfill(dest,x+3*size,y+3*size,x+12*size,y+12*size,vc(4));
17684 }
17685
17686 if(buf)
17687 destroy_bitmap(buf);
17688
17689 if(buf2)
17690 destroy_bitmap(buf2);
17691 }
17692 else
17693 {
17694 if(combobuf[combo->combo].tile>0)
17695 {
17696 rectfill(dest,x,y,x+16*size-1,y+16*size-1,0);
17697 put_combo(dest, x, y, combo->combo, combo->cset, 0, 0, size);
17698 }
17699 else
17700 {
17701 rectfill(dest,x,y,x+16*size-1,y+16*size-1,0);
17702 rectfill(dest,x+3*size,y+3*size,x+12*size,y+12*size,vc(4));
17703 }
17704 }
17705 }
17706
17707 int32_t d_comboat_proc(int32_t msg,DIALOG *d,int32_t)
17708 {
17709 switch(msg)
17710 {
17711 case MSG_CLICK:
17712 {
17713 int32_t c2;
17714 int32_t cs;
17715 c2=temp_aliases[comboa_cnt].combo;
17716 cs=temp_aliases[comboa_cnt].cset;
17717
17718 if(gui_mouse_b()&2) //right mouse button
17719 {
17720 if(c2==0&&cs==0&&!(gui_mouse_b()&1))
17721 {
17722 return D_O_K;
17723 }
17724
17725 temp_aliases[comboa_cnt].combo=0;
17726 temp_aliases[comboa_cnt].cset=0;
17727 }
17728
17729 if(gui_mouse_b()&1) //left mouse button
17730 {
17731 if(select_combo_2(c2, cs))
17732 {
17733 temp_aliases[comboa_cnt].combo=c2;
17734 temp_aliases[comboa_cnt].cset=cs;
17735 }
17736
17737 return D_REDRAW;
17738 }
17739 else
17740 {
17741 return D_REDRAWME;
17742 }
17743 }
17744 break;
17745
17746 case MSG_DRAW:
17747 draw_combo_alias_thumbnail(screen, &temp_aliases[comboa_cnt], d->x-1, d->y-1,2);
17748 break;
17749
17750 default:
17751 break;
17752 }
17753
17754 return D_O_K;
17755 }
17756
17757 int32_t d_comboa_radio_proc(int32_t msg,DIALOG *d,int32_t c);
17758
17759 static DIALOG orgcomboa_dlg[] =
17760 {
17761 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
17762 { jwin_win_proc, 0, 0, 200, 161, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Organize Combo Aliases", NULL, NULL },
17763 { jwin_button_proc, 27, 130, 61, 21, vc(14), vc(1), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
17764 { jwin_button_proc, 112, 130, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
17765
17766 { jwin_radio_proc, 10, 40, 33, 9, vc(14), vc(1), 0, 0, 0, 0, (void*) "Copy", NULL, NULL },
17767 { jwin_text_proc, 10, 50, 33, 9, 0, 0, 0, 0, 0, 0, (void *) "", NULL, NULL },
17768 // { jwin_radio_proc, 10, 50, 33, 9, vc(14), vc(1), 0, 0, 0, 0, (void*) "Move", NULL, NULL },
17769 { jwin_radio_proc, 10, 60, 33, 9, vc(14), vc(1), 0, 0, 0, 0, (void*) "Swap", NULL, NULL },
17770 /* 6 */ { jwin_edit_proc, 110, 35, 32, 16, vc(12), vc(1), 0, 0, 4, 0, NULL, NULL, NULL },
17771 { jwin_edit_proc, 110, 55, 32, 16, vc(12), vc(1), 0, 0, 4, 0, NULL, NULL, NULL },
17772 { jwin_text_proc, 60, 40, 80, 8, 0, 0, 0, 0, 0, 0, (void *) "Source", NULL, NULL },
17773 { jwin_text_proc, 60, 60, 80, 8, 0, 0, 0, 0, 0, 0, (void *) "Dest", NULL, NULL},
17774 { jwin_radio_proc, 10, 80, 60, 9, vc(14), vc(1), 0, 0, 0, 0, (void*) "Insert new (before source)", NULL, NULL },
17775 { jwin_radio_proc, 10, 100, 60, 9, vc(14), vc(1), 0, 0, 0, 0, (void*) "Delete source", NULL, NULL },
17776 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
17777 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
17778 };
17779
17780 static DIALOG newcomboa_dlg[] =
17781 {
17782 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
17783 { jwin_win_proc, 0, 0, 200, 161, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Combo Alias Properties", NULL, NULL },
17784 { jwin_button_proc, 27, 130, 61, 21, vc(14), vc(1), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
17785 { jwin_button_proc, 112, 130, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
17786 { jwin_text_proc, 24, 34, 80, 8, 0, 0, 0, 0, 0, 0, (void *) "Alias Width", NULL, NULL },
17787 { jwin_text_proc, 24, 52, 80, 8, 0, 0, 0, 0, 0, 0, (void *) "Alias Height", NULL, NULL },
17788 { jwin_text_proc, 24, 70, 100, 8, 0, 0, 0, 0, 0, 0, (void *) "Layers to Draw On:", NULL, NULL },
17789 { jwin_edit_proc, 104, 30, 28-6, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
17790 { jwin_edit_proc, 122, 48, 28-6, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
17791 { jwin_check_proc, 24, 86, 24, 9, vc(12), vc(1), 0, 0, 1, 0, (void *) "1", NULL, NULL },
17792 { jwin_check_proc, 50, 86, 24, 9, vc(12), vc(1), 0, 0, 1, 0, (void *) "2", NULL, NULL },
17793 { jwin_check_proc, 76, 86, 24, 9, vc(12), vc(1), 0, 0, 1, 0, (void *) "3", NULL, NULL },
17794 { jwin_check_proc, 102, 86, 24, 9, vc(12), vc(1), 0, 0, 1, 0, (void *) "4", NULL, NULL },
17795 { jwin_check_proc, 128, 86, 24, 9, vc(12), vc(1), 0, 0, 1, 0, (void *) "5", NULL, NULL },
17796 { jwin_check_proc, 154, 86, 24, 9, vc(12), vc(1), 0, 0, 1, 0, (void *) "6", NULL, NULL },
17797
17798
17799 // { jwin_text_proc, 24, 106, 80, 8, 0, 0, 0, 0, 0, 0, (void *) "Copy to :", NULL, NULL },
17800 //15
17801 // { jwin_edit_proc, 100, 100, 28-6, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
17802 // { jwin_check_proc, 84, 106, 24, 9, vc(12), vc(1), 0, 0, 1, 0, (void *) "", NULL, NULL },
17803
17804 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
17805 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
17806 };
17807
17808 bool swapComboAlias(int32_t source, int32_t dest)
17809 {
17810 if(source==dest)
17811 return false;
17812 zc_swap(temp_aliases[source],temp_aliases[dest]);
17813 return true;
17814 }
17815
17816
17817 bool copyComboAlias(int32_t source, int32_t dest)
17818 {
17819 if(source == dest)
17820 return false;
17821 temp_aliases[dest] = temp_aliases[source];
17822 return true;
17823 }
17824
17825 int32_t getcurrentcomboalias();
17826
17827 int32_t onOrgComboAliases()
17828 {
17829 char cSrc[8];
17830 char cDest[8];
17831 sprintf(cSrc,"%d", getcurrentcomboalias());
17832 strcpy(cDest,cSrc);
17833 int32_t iSrc = 0;
17834 int32_t iDest = 0;
17835
17836 //sprintf(cSrc,"0");
17837 //sprintf(cDest,"0");
17838 orgcomboa_dlg[0].dp2=get_zc_font(font_lfont);
17839 orgcomboa_dlg[6].dp= cSrc;
17840 orgcomboa_dlg[7].dp= cDest;
17841 int32_t ret = 1;
17842 large_dialog(orgcomboa_dlg);
17843 do
17844 {
17845 iSrc = atoi((char*)orgcomboa_dlg[6].dp);
17846 iDest = atoi((char*)orgcomboa_dlg[7].dp);
17847 ret = do_zqdialog(orgcomboa_dlg,-1);
17848
17849 if(ret!=1) return ret;
17850
17851 if((atoi((char*) orgcomboa_dlg[6].dp))<0 || (atoi((char*) orgcomboa_dlg[6].dp)) > MAXCOMBOALIASES-1)
17852 {
17853 char buf[100];
17854 snprintf(buf, 100, "Invalid source (range 0-%d)", MAXCOMBOALIASES-1);
17855 buf[99]='\0';
17856 jwin_alert("Error",buf,NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
17857 ret = 1;
17858 }
17859
17860 // 10,11=ins, del
17861 if(orgcomboa_dlg[10].flags & D_SELECTED) //insert
17862 {
17863 for(int32_t j=MAXCOMBOALIASES-1; j>(atoi((char*) orgcomboa_dlg[6].dp)); --j)
17864 copyComboAlias(j-1,j);
17865 ret = -1;
17866 }
17867
17868 if(orgcomboa_dlg[11].flags & D_SELECTED) //delete
17869 {
17870 for(int32_t j=(atoi((char*) orgcomboa_dlg[6].dp)); j<MAXCOMBOALIASES-1; ++j)
17871 copyComboAlias(j+1,j);
17872 ret = -1;
17873 }
17874
17875 if((atoi((char*) orgcomboa_dlg[6].dp)) == (atoi((char*) orgcomboa_dlg[7].dp)))
17876 {
17877 jwin_alert("Error","Source and dest can't be the same.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
17878 ret = 1;
17879 }
17880
17881 if((atoi((char*) orgcomboa_dlg[7].dp)) < 0 || (atoi((char*) orgcomboa_dlg[7].dp)) > MAXCOMBOALIASES-1)
17882 {
17883 char buf[100];
17884 snprintf(buf, 100, "Invalid dest (range 0-%d)", MAXCOMBOALIASES-1);
17885 buf[99]='\0';
17886
17887 jwin_alert("Error",buf,NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
17888 ret = 1;
17889 }
17890
17891 if(orgcomboa_dlg[3].flags & D_SELECTED) //copy
17892 {
17893 copyComboAlias((atoi((char*) orgcomboa_dlg[6].dp)),(atoi((char*) orgcomboa_dlg[7].dp)));
17894 ret = -1;
17895 }
17896
17897 if(orgcomboa_dlg[5].flags & D_SELECTED) //swap
17898 {
17899 swapComboAlias((atoi((char*) orgcomboa_dlg[6].dp)),(atoi((char*) orgcomboa_dlg[7].dp)));
17900 ret = -1;
17901 }
17902 }
17903 while(ret==1);
17904 return ret;
17905 }
17906
17907 int32_t onNewComboAlias()
17908 {
17909 combo_alias *combo;
17910 combo = &temp_aliases[comboa_cnt];
17911
17912 char cwidth[5];
17913 char cheight[5];
17914 // char cp[3];
17915
17916 word temp_combos[16*11*7];
17917 byte temp_csets[16*11*7];
17918 sprintf(cwidth, "%d", combo->width+1);
17919 sprintf(cheight, "%d", combo->height+1);
17920 int32_t old_count = (comboa_lmasktotal(combo->layermask)+1)*(combo->width+1)*(combo->height+1);
17921 int32_t old_width=combo->width;
17922 int32_t old_height=combo->height;
17923 int32_t oldlayer=combo->layermask;
17924
17925 for(int32_t i=0; i<old_count; i++)
17926 {
17927 temp_csets[i] = combo->csets[i];
17928 temp_combos[i] = combo->combos[i];
17929 }
17930
17931 newcomboa_dlg[0].dp2 = get_zc_font(font_lfont);
17932 newcomboa_dlg[6].dp = cwidth;
17933 newcomboa_dlg[7].dp = cheight;
17934 newcomboa_dlg[8].flags = (combo->layermask&1)? D_SELECTED : 0;
17935 newcomboa_dlg[9].flags = (combo->layermask&2)? D_SELECTED : 0;
17936 newcomboa_dlg[10].flags = (combo->layermask&4)? D_SELECTED : 0;
17937 newcomboa_dlg[11].flags = (combo->layermask&8)? D_SELECTED : 0;
17938 newcomboa_dlg[12].flags = (combo->layermask&16)? D_SELECTED : 0;
17939 newcomboa_dlg[13].flags = (combo->layermask&32)? D_SELECTED : 0;
17940
17941 large_dialog(newcomboa_dlg);
17942
17943 int32_t ret = do_zqdialog(newcomboa_dlg,-1);
17944
17945 if(ret==1)
17946 {
17947 combo->width = ((atoi(cwidth)-1)<16)?zc_max(0,(atoi(cwidth)-1)):15;
17948 combo->height = ((atoi(cheight)-1)<11)?zc_max(0,(atoi(cheight)-1)):10;
17949 combo->layermask=0;
17950 combo->layermask |= (newcomboa_dlg[8].flags&D_SELECTED)?1:0;
17951 combo->layermask |= (newcomboa_dlg[9].flags&D_SELECTED)?2:0;
17952 combo->layermask |= (newcomboa_dlg[10].flags&D_SELECTED)?4:0;
17953 combo->layermask |= (newcomboa_dlg[11].flags&D_SELECTED)?8:0;
17954 combo->layermask |= (newcomboa_dlg[12].flags&D_SELECTED)?16:0;
17955 combo->layermask |= (newcomboa_dlg[13].flags&D_SELECTED)?32:0;
17956
17957 int32_t new_count = (comboa_lmasktotal(combo->layermask)+1)*(combo->width+1)*(combo->height+1);
17958
17959 combo->combos.clear();
17960 combo->csets.clear();
17961
17962 int32_t j=1;
17963 int32_t old_size=(old_width+1)*(old_height+1);
17964 int32_t new_start[7] =
17965 {
17966 0,
17967 ((combo->width+1)*(combo->height+1)*(1)),
17968 ((combo->width+1)*(combo->height+1)*(2)),
17969 ((combo->width+1)*(combo->height+1)*(3)),
17970 ((combo->width+1)*(combo->height+1)*(4)),
17971 ((combo->width+1)*(combo->height+1)*(5)),
17972 ((combo->width+1)*(combo->height+1)*(6))
17973 };
17974 int32_t new_layers[6] = {0,0,0,0,0,0};
17975 int32_t temp_layer = combo->layermask;
17976 int32_t temp_old = oldlayer;
17977 int32_t old_layers[6] = {0,0,0,0,0,0};
17978 int32_t k=1;
17979
17980 for(int32_t i=0; (i<6)&&(temp_layer!=0); j++,temp_layer>>=1,temp_old>>=1)
17981 {
17982 if(temp_layer&1)
17983 {
17984 new_layers[i] = j;
17985 //if(oldlayer&(1<<(j-1))) old_layers[i] = k++;
17986 i++;
17987 }
17988
17989 if(temp_old&1)
17990 {
17991 if(temp_layer&1)
17992 {
17993 old_layers[i-1] = k;
17994 }
17995
17996 k++;
17997 }
17998 }
17999
18000 for(int32_t i=0; i<new_count; i++)
18001 {
18002 if(i>=new_start[6])
18003 {
18004 //oldl=oldlayer>>(new_layers[5]-1);
18005 j=i-new_start[6];
18006
18007 if(((j/(combo->width+1))<=old_height)&&((j%(combo->width+1))<=old_width)&&(oldlayer&(1<<(new_layers[5]-1))))
18008 {
18009 combo->combos[i] = temp_combos[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[5])];
18010 combo->csets[i] = temp_csets[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[5])];
18011 }
18012 else
18013 {
18014 combo->combos[i] = 0;
18015 combo->csets[i] = 0;
18016 }
18017 }
18018 else if(i>=new_start[5])
18019 {
18020 //oldl=oldlayer>>(new_layers[4]-1);
18021 j=i-new_start[5];
18022
18023 if(((j/(combo->width+1))<=old_height)&&((j%(combo->width+1))<=old_width)&&(oldlayer&(1<<(new_layers[4]-1))))
18024 {
18025 combo->combos[i] = temp_combos[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[4])];
18026 combo->csets[i] = temp_csets[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[4])];
18027 }
18028 else
18029 {
18030 combo->combos[i] = 0;
18031 combo->csets[i] = 0;
18032 }
18033 }
18034 else if(i>=new_start[4])
18035 {
18036 //oldl=oldlayer>>(new_layers[3]-1);
18037 j=i-new_start[4];
18038
18039 if(((j/(combo->width+1))<=old_height)&&((j%(combo->width+1))<=old_width)&&(oldlayer&(1<<(new_layers[3]-1))))
18040 {
18041 combo->combos[i] = temp_combos[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[3])];
18042 combo->csets[i] = temp_csets[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[3])];
18043 }
18044 else
18045 {
18046 combo->combos[i] = 0;
18047 combo->csets[i] = 0;
18048 }
18049 }
18050 else if(i>=new_start[3])
18051 {
18052 //oldl=oldlayer>>(new_layers[2]-1);
18053 j=i-new_start[3];
18054
18055 if(((j/(combo->width+1))<=old_height)&&((j%(combo->width+1))<=old_width)&&(oldlayer&(1<<(new_layers[2]-1))))
18056 {
18057 combo->combos[i] = temp_combos[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[2])];
18058 combo->csets[i] = temp_csets[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[2])];
18059 }
18060 else
18061 {
18062 combo->combos[i] = 0;
18063 combo->csets[i] = 0;
18064 }
18065 }
18066 else if(i>=new_start[2])
18067 {
18068 //oldl=oldlayer>>(new_layers[1]-1);
18069 j=i-new_start[2];
18070
18071 if(((j/(combo->width+1))<=old_height)&&((j%(combo->width+1))<=old_width)&&(oldlayer&(1<<(new_layers[1]-1))))
18072 {
18073 combo->combos[i] = temp_combos[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[1])];
18074 combo->csets[i] = temp_csets[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[1])];
18075 }
18076 else
18077 {
18078 combo->combos[i] = 0;
18079 combo->csets[i] = 0;
18080 }
18081 }
18082 else if(i>=new_start[1])
18083 {
18084 //oldl=oldlayer>>(new_layers[0]-1);
18085 j=i-new_start[1];
18086
18087 if(((j/(combo->width+1))<=old_height)&&((j%(combo->width+1))<=old_width)&&(oldlayer&(1<<(new_layers[0]-1))))
18088 {
18089 combo->combos[i] = temp_combos[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[0])];
18090 combo->csets[i] = temp_csets[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[0])];
18091 }
18092 else
18093 {
18094 combo->combos[i] = 0;
18095 combo->csets[i] = 0;
18096 }
18097 }
18098 else if(i>=new_start[0])
18099 {
18100 if(((i/(combo->width+1))<=old_height)&&((i%(combo->width+1))<=old_width))
18101 {
18102 combo->combos[i] = temp_combos[(i%(combo->width+1))+((old_width+1)*(i/(combo->width+1)))];
18103 combo->csets[i] = temp_csets[(i%(combo->width+1))+((old_width+1)*(i/(combo->width+1)))];
18104 }
18105 else
18106 {
18107 combo->combos[i] = 0;
18108 combo->csets[i] = 0;
18109 }
18110 }
18111 }
18112
18113 set_comboaradio(combo->layermask);
18114 }
18115
18116 return ret;
18117 }
18118
18119 int32_t d_orgcomboa_proc(int32_t msg, DIALOG *d, int32_t c)
18120 {
18121 //these are here to bypass compiler warnings about unused arguments
18122 c=c;
18123
18124 int32_t down=0;
18125 int32_t selected=(d->flags&D_SELECTED)?1:0;
18126 int32_t last_draw;
18127
18128 switch(msg)
18129 {
18130
18131 case MSG_DRAW:
18132 {
18133 FONT *tfont=font;
18134 font=get_zc_font(font_lfont_l);
18135 jwin_draw_text_button(screen, d->x, d->y, d->w, d->h, (char*)d->dp, d->flags, true);
18136 font=tfont;
18137 }
18138 break;
18139
18140 case MSG_WANTFOCUS:
18141 return D_WANTFOCUS;
18142
18143 case MSG_KEY:
18144 /* close dialog? */
18145 onOrgComboAliases();
18146 return D_REDRAW;
18147
18148 /* or just toggle */
18149 /*d->flags ^= D_SELECTED;
18150 object_message(d, MSG_DRAW, 0);
18151 break;*/
18152
18153 case MSG_CLICK:
18154 last_draw = 0;
18155
18156 /* track the mouse until it is released */
18157 while(gui_mouse_b())
18158 {
18159 down = mouse_in_rect(d->x, d->y, d->w, d->h);
18160
18161 /* redraw? */
18162 if(last_draw != down)
18163 {
18164 if(down != selected)
18165 d->flags |= D_SELECTED;
18166 else
18167 d->flags &= ~D_SELECTED;
18168
18169 object_message(d, MSG_DRAW, 0);
18170 last_draw = down;
18171 }
18172
18173 /* let other objects continue to animate */
18174 broadcast_dialog_message(MSG_IDLE, 0);
18175 }
18176
18177 /* redraw in normal state */
18178 if(down)
18179 {
18180 if(d->flags&D_EXIT)
18181 {
18182 d->flags &= ~D_SELECTED;
18183 object_message(d, MSG_DRAW, 0);
18184 }
18185 }
18186
18187 /* should we close the dialog? */
18188 if(down)
18189 {
18190 onOrgComboAliases();
18191 return D_REDRAW;
18192 }
18193
18194 break;
18195 }
18196
18197 return D_O_K;
18198 }
18199
18200 int32_t d_comboabutton_proc(int32_t msg, DIALOG *d, int32_t c)
18201 {
18202 //these are here to bypass compiler warnings about unused arguments
18203 c=c;
18204
18205 int32_t down=0;
18206 int32_t selected=(d->flags&D_SELECTED)?1:0;
18207 int32_t last_draw;
18208
18209 switch(msg)
18210 {
18211
18212 case MSG_DRAW:
18213 {
18214 FONT *tfont=font;
18215 font=get_zc_font(font_lfont_l);
18216 jwin_draw_text_button(screen, d->x, d->y, d->w, d->h, (char*)d->dp, d->flags, true);
18217 font=tfont;
18218 }
18219 break;
18220
18221 case MSG_WANTFOCUS:
18222 return D_WANTFOCUS;
18223
18224 case MSG_KEY:
18225 /* close dialog? */
18226 onNewComboAlias();
18227 return D_REDRAW;
18228
18229 /* or just toggle */
18230 /*d->flags ^= D_SELECTED;
18231 object_message(d, MSG_DRAW, 0);
18232 break;*/
18233
18234 case MSG_CLICK:
18235 last_draw = 0;
18236
18237 /* track the mouse until it is released */
18238 while(gui_mouse_b())
18239 {
18240 down = mouse_in_rect(d->x, d->y, d->w, d->h);
18241
18242 /* redraw? */
18243 if(last_draw != down)
18244 {
18245 if(down != selected)
18246 d->flags |= D_SELECTED;
18247 else
18248 d->flags &= ~D_SELECTED;
18249
18250 object_message(d, MSG_DRAW, 0);
18251 last_draw = down;
18252 }
18253
18254 /* let other objects continue to animate */
18255 broadcast_dialog_message(MSG_IDLE, 0);
18256 }
18257
18258 /* redraw in normal state */
18259 if(down)
18260 {
18261 if(d->flags&D_EXIT)
18262 {
18263 d->flags &= ~D_SELECTED;
18264 object_message(d, MSG_DRAW, 0);
18265 }
18266 }
18267
18268 /* should we close the dialog? */
18269 if(down)
18270 {
18271 onNewComboAlias();
18272 return D_REDRAW;
18273 }
18274
18275 break;
18276 }
18277
18278 return D_O_K;
18279 }
18280
18281 int32_t d_comboacheck_proc(int32_t msg, DIALOG *d, int32_t c)
18282 {
18283 int32_t temp = d->flags&D_SELECTED;
18284 int32_t ret=jwin_checkfont_proc(msg,d,c);
18285
18286 if(temp != (d->flags&D_SELECTED))
18287 {
18288 return D_REDRAW;
18289 }
18290
18291 return ret;
18292 }
18293
18294 12 static ListData comboa_list(comboalist, &font);
18295
18296 static DIALOG editcomboa_dlg[] =
18297 {
18298 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
18299 { jwin_win_proc, 0, 0, 320, 240, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Combo Alias Edit", NULL, NULL },
18300 { jwin_button_proc, 148, 212, 61, 21, vc(14), vc(1), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
18301 { jwin_button_proc, 232, 212, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
18302 { jwin_frame_proc, 4+121, 28+81, 1, 1, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
18303 { d_comboabutton_proc, 25, 212, 81, 21, vc(14), vc(1), 'p', D_EXIT, 0, 0, (void *) "&Properties", NULL, NULL },
18304 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
18305 { d_comboa_radio_proc, 285, 44, 30, 8+1, vc(14), vc(1), 0, D_SELECTED, 0, 0, (void *) "0", NULL, NULL },
18306 { d_comboa_radio_proc, 285, 54, 30, 8+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "1", NULL, NULL },
18307 { d_comboa_radio_proc, 285, 64, 30, 8+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "2", NULL, NULL },
18308 { d_comboa_radio_proc, 285, 74, 30, 8+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "3", NULL, NULL },
18309 { d_comboa_radio_proc, 285, 84, 30, 8+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "4", NULL, NULL },
18310
18311 { d_comboa_radio_proc, 285, 94, 30, 8+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "5", NULL, NULL },
18312 { d_comboa_radio_proc, 285, 104, 30, 8+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "6", NULL, NULL },
18313 { d_comboacheck_proc, 285, 164, 17, 9, vc(12), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
18314 { d_comboa_proc, 6, 27, 256, 176, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
18315 { jwin_ctext_proc, 290, 176, 27, 8, 0, 0, 0, 0, 0, 0, (void *) "Only Show", NULL, NULL },
18316 { jwin_ctext_proc, 290, 186, 27, 8, 0, 0, 0, 0, 0, 0, (void *) "Current", NULL, NULL },
18317 { jwin_ctext_proc, 290, 196, 27, 8, 0, 0, 0, 0, 0, 0, (void *) "Layer", NULL, NULL },
18318 { jwin_ctext_proc, 290, 122, 27, 8, 0, 0, 0, 0, 0, 0, (void *) "Thumbnail", NULL, NULL },
18319 { jwin_frame_proc, 280, 132, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
18320 { d_comboat_proc, 282, 134, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
18321
18322 //21
18323 { d_orgcomboa_proc, 106, 212, 21, 21, vc(14), vc(1), 'p', D_EXIT, 0, 0, (void *) "&Org", NULL, NULL },
18324 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
18325 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
18326 };
18327
18328 int32_t getcurrentcomboalias()
18329 {
18330 return editcomboa_dlg[5].d1;
18331 }
18332
18333 int32_t d_comboa_radio_proc(int32_t msg,DIALOG *d,int32_t c)
18334 {
18335 int32_t temp = layer_cnt;
18336 int32_t ret = jwin_radiofont_proc(msg,d,c);
18337
18338 if(editcomboa_dlg[6].flags&D_SELECTED) layer_cnt=0;
18339 else if(editcomboa_dlg[7].flags&D_SELECTED) layer_cnt=1;
18340 else if(editcomboa_dlg[8].flags&D_SELECTED) layer_cnt=2;
18341 else if(editcomboa_dlg[9].flags&D_SELECTED) layer_cnt=3;
18342 else if(editcomboa_dlg[10].flags&D_SELECTED) layer_cnt=4;
18343 else if(editcomboa_dlg[11].flags&D_SELECTED) layer_cnt=5;
18344 else if(editcomboa_dlg[12].flags&D_SELECTED) layer_cnt=6;
18345
18346 if(temp != layer_cnt)
18347 {
18348 return D_REDRAW;
18349 }
18350
18351 return ret;
18352 }
18353
18354 int32_t set_comboaradio(byte layermask)
18355 {
18356 if(editcomboa_dlg[7].flags&D_SELECTED) editcomboa_dlg[7].flags &= ~D_SELECTED;
18357
18358 if(editcomboa_dlg[8].flags&D_SELECTED) editcomboa_dlg[8].flags &= ~D_SELECTED;
18359
18360 if(editcomboa_dlg[9].flags&D_SELECTED) editcomboa_dlg[9].flags &= ~D_SELECTED;
18361
18362 if(editcomboa_dlg[10].flags&D_SELECTED) editcomboa_dlg[10].flags &= ~D_SELECTED;
18363
18364 if(editcomboa_dlg[11].flags&D_SELECTED) editcomboa_dlg[11].flags &= ~D_SELECTED;
18365
18366 if(editcomboa_dlg[12].flags&D_SELECTED) editcomboa_dlg[12].flags &= ~D_SELECTED;
18367
18368 if(!(layermask&1)) editcomboa_dlg[7].flags |= D_DISABLED;
18369 else editcomboa_dlg[7].flags &= ~D_DISABLED;
18370
18371 if(!(layermask&2)) editcomboa_dlg[8].flags |= D_DISABLED;
18372 else editcomboa_dlg[8].flags &= ~D_DISABLED;
18373
18374 if(!(layermask&4)) editcomboa_dlg[9].flags |= D_DISABLED;
18375 else editcomboa_dlg[9].flags &= ~D_DISABLED;
18376
18377 if(!(layermask&8)) editcomboa_dlg[10].flags |= D_DISABLED;
18378 else editcomboa_dlg[10].flags &= ~D_DISABLED;
18379
18380 if(!(layermask&16)) editcomboa_dlg[11].flags |= D_DISABLED;
18381 else editcomboa_dlg[11].flags &= ~D_DISABLED;
18382
18383 if(!(layermask&32)) editcomboa_dlg[12].flags |= D_DISABLED;
18384 else editcomboa_dlg[12].flags &= ~D_DISABLED;
18385
18386 editcomboa_dlg[6].flags |= D_SELECTED;
18387 layer_cnt=0;
18388 return 1;
18389 }
18390
18391 int32_t onEditComboPool()
18392 {
18393 call_cpool_dlg(combo_pool_pos);
18394 return D_O_K;
18395 }
18396 int32_t onEditAutoCombo()
18397 {
18398 call_autocombo_dlg(combo_auto_pos);
18399 return D_O_K;
18400 }
18401 int32_t onEditComboAlias()
18402 {
18403 comboa_cnt = combo_apos;
18404 reset_combo_animations();
18405 reset_combo_animations2();
18406
18407 for(int32_t i=0; i<MAXCOMBOALIASES; i++)
18408 temp_aliases[i] = combo_aliases[i];
18409
18410 editcomboa_dlg[0].dp2 = get_zc_font(font_lfont);
18411 set_comboaradio(temp_aliases[comboa_cnt].layermask);
18412 editcomboa_dlg[5].d1 = comboa_cnt;
18413
18414 bool small_d1 = editcomboa_dlg[0].d1==0;
18415 large_dialog(editcomboa_dlg,2);
18416
18417 if(small_d1)
18418 {
18419 for(int32_t i=6; i<=12; i++)
18420 {
18421 editcomboa_dlg[i].w=30*1.5;
18422 editcomboa_dlg[i].h=9*1.5;
18423 }
18424
18425 editcomboa_dlg[13].w=17*1.5;
18426 editcomboa_dlg[13].h=9*1.5;
18427 editcomboa_dlg[4].w=81*1.5;
18428 editcomboa_dlg[4].h=21*1.5;
18429 editcomboa_dlg[4].dp2=get_zc_font(font_lfont_l);
18430 editcomboa_dlg[21].w=21*1.5;
18431 editcomboa_dlg[21].h=21*1.5;
18432 editcomboa_dlg[21].dp2=get_zc_font(font_lfont_l);
18433 }
18434
18435 int32_t ret=do_zqdialog(editcomboa_dlg,-1);
18436
18437 if(ret==1)
18438 {
18439 saved=false;
18440
18441 for(int32_t i=0; i<MAXCOMBOALIASES; i++)
18442 combo_aliases[i] = temp_aliases[i];
18443 }
18444
18445 setup_combo_animations();
18446 setup_combo_animations2();
18447 return D_O_K;
18448 }
18449 void call_calias_dlg(int index)
18450 {
18451 combo_apos = comboa_cnt = index;
18452 onEditComboAlias();
18453 }
18454
18455 static char ffcombo_str_buf[MAXFFCS];
18456 static char fflink_str_buf[MAXFFCS];
18457
18458 BITMAP* ffcur;
18459
18460 const char *ffcombolist(int32_t index, int32_t *list_size)
18461 {
18462 if(index>=0)
18463 {
18464 bound(index,0,MAXFFCS-1);
18465 sprintf(ffcombo_str_buf,"%d",index+1);
18466 return ffcombo_str_buf;
18467 }
18468
18469 *list_size=MAXFFCS;
18470 return NULL;
18471 }
18472
18473 12 static ListData ffcombo_list(ffcombolist, &font);
18474
18475 static DIALOG ffcombo_sel_dlg[] =
18476 {
18477 12 { jwin_win_proc, 0, 0, 200, 179, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Choose Freeform Combo", NULL, NULL },
18478 12 { jwin_button_proc, 35, 152, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Edit", NULL, NULL },
18479 12 { jwin_button_proc, 104, 152, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Done", NULL, NULL },
18480 12 { d_ffcombolist_proc, 11, 24, 49, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 1, 0, (void *) &ffcombo_list, NULL, NULL },
18481 12 { d_comboframe_proc, 68, 23, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
18482 12 { d_bitmap_proc, 70, 25, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
18483 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
18484 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
18485 };
18486
18487 int32_t d_ffcombolist_proc(int32_t msg,DIALOG *d,int32_t c)
18488 {
18489 int32_t ret = jwin_droplist_proc(msg,d,c);
18490 int32_t d1 = d->d1;
18491 int32_t x=ffcombo_sel_dlg[0].x;
18492 int32_t y=ffcombo_sel_dlg[0].y;
18493 FONT *tempfont=(font);
18494 int32_t x2=text_length(tempfont, "Move Delay:")+4;
18495
18496 switch(msg)
18497 {
18498 case MSG_DRAW:
18499 if(!ffcur) return D_O_K;
18500
18501 BITMAP *buf = create_bitmap_ex(8,16,16);
18502
18503 if(buf)
18504 {
18505 clear_bitmap(buf);
18506 putcombo(buf,0,0,Map.CurrScr()->ffcs[d1].data,Map.CurrScr()->ffcs[d1].cset);
18507 stretch_blit(buf, ffcur, 0,0, 16, 16, 0, 0, ffcur->w, ffcur->h);
18508 destroy_bitmap(buf);
18509 }
18510
18511 object_message(&ffcombo_sel_dlg[5],MSG_DRAW,0);
18512
18513 int32_t xd = x+int32_t(68*1.5);
18514 int32_t y2 = y+int32_t(55*1.5);
18515 int32_t yd = 9;
18516
18517 rectfill(screen,xd,y2,xd+x2+100,y2+yd*14,jwin_pal[jcBOX]);
18518
18519 textprintf_ex(screen,tempfont,xd,y2,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"Combo #:");
18520 textprintf_ex(screen,tempfont,xd+x2,y2,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%d",Map.CurrScr()->ffcs[d1].data);
18521
18522 textprintf_ex(screen,tempfont,xd,y2+yd,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"CSet #:");
18523 textprintf_ex(screen,tempfont,xd+x2,y2+yd,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%d",Map.CurrScr()->ffcs[d1].cset);
18524
18525 textprintf_ex(screen,tempfont,xd,y2+yd*2,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"X Pos:");
18526 textprintf_ex(screen,tempfont,xd+x2,y2+yd*2,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%.4f",Map.CurrScr()->ffcs[d1].x.getFloat());
18527
18528 textprintf_ex(screen,tempfont,xd,y2+yd*3,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"Y Pos:");
18529 textprintf_ex(screen,tempfont,xd+x2,y2+yd*3,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%.4f",Map.CurrScr()->ffcs[d1].y.getFloat());
18530
18531 textprintf_ex(screen,tempfont,xd,y2+yd*4,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"X Speed:");
18532 textprintf_ex(screen,tempfont,xd+x2,y2+yd*4,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%.4f",Map.CurrScr()->ffcs[d1].vx.getFloat());
18533
18534 textprintf_ex(screen,tempfont,xd,y2+yd*5,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"Y Speed:");
18535 textprintf_ex(screen,tempfont,xd+x2,y2+yd*5,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%.4f",Map.CurrScr()->ffcs[d1].vy.getFloat());
18536
18537 textprintf_ex(screen,tempfont,xd,y2+yd*6,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"X Accel:");
18538 textprintf_ex(screen,tempfont,xd+x2,y2+yd*6,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%.4f",Map.CurrScr()->ffcs[d1].ax.getFloat());
18539
18540 textprintf_ex(screen,tempfont,xd,y2+yd*7,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"Y Accel:");
18541 textprintf_ex(screen,tempfont,xd+x2,y2+yd*7,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%.4f",Map.CurrScr()->ffcs[d1].ay.getFloat());
18542
18543 textprintf_ex(screen,tempfont,xd,y2+yd*8,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"Linked To:");
18544 textprintf_ex(screen,tempfont,xd+x2,y2+yd*8,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%d",Map.CurrScr()->ffcs[d1].link);
18545
18546 textprintf_ex(screen,tempfont,xd,y2+yd*9,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"Move Delay:");
18547 textprintf_ex(screen,tempfont,xd+x2,y2+yd*9,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%d",Map.CurrScr()->ffcs[d1].delay);
18548
18549 textprintf_ex(screen,tempfont,xd,y2+yd*10,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"Combo W:");
18550 textprintf_ex(screen,tempfont,xd+x2,y2+yd*10,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%d",(Map.CurrScr()->ffEffectWidth(d1)));
18551
18552 textprintf_ex(screen,tempfont,xd,y2+yd*11,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"Combo H:");
18553 textprintf_ex(screen,tempfont,xd+x2,y2+yd*11,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%d",(Map.CurrScr()->ffEffectHeight(d1)));
18554
18555 textprintf_ex(screen,tempfont,xd,y2+yd*12,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"Tile W:");
18556 textprintf_ex(screen,tempfont,xd+x2,y2+yd*12,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%d",(Map.CurrScr()->ffTileWidth(d1)));
18557
18558 textprintf_ex(screen,tempfont,xd,y2+yd*13,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"Tile H:");
18559 textprintf_ex(screen,tempfont,xd+x2,y2+yd*13,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%d",(Map.CurrScr()->ffTileHeight(d1)));
18560
18561 break;
18562 }
18563
18564 return ret;
18565 }
18566 int32_t onSelectFFCombo()
18567 {
18568 ffcombo_sel_dlg[0].dp2 = get_zc_font(font_lfont);
18569 ffcombo_sel_dlg[3].d1 = ff_combo;
18570 ffcur = create_bitmap_ex(8,32,32);
18571
18572 if(!ffcur) return D_O_K;
18573
18574 Map.CurrScr()->ensureFFC(MAXFFCS - 1);
18575 putcombo(ffcur,0,0,Map.CurrScr()->ffcs[ff_combo].data,Map.CurrScr()->ffcs[ff_combo].cset);
18576 ffcombo_sel_dlg[5].dp = ffcur;
18577
18578 bool resize = !(ffcombo_sel_dlg[0].d1);
18579 large_dialog(ffcombo_sel_dlg);
18580
18581 if(resize)
18582 {
18583 ffcombo_sel_dlg[5].x--;
18584 ffcombo_sel_dlg[5].y--;
18585 }
18586
18587 int32_t ret=do_zqdialog(ffcombo_sel_dlg,0);
18588
18589 while(ret==1)
18590 {
18591 ff_combo = ffcombo_sel_dlg[3].d1;
18592 mapscr* scr = active_visible_screen ? active_visible_screen->scr : Map.CurrScr();
18593 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
18594 call_ffc_dialog(ff_combo, scr, screen);
18595 ret=do_zqdialog(ffcombo_sel_dlg,0);
18596 }
18597
18598 destroy_bitmap(ffcur);
18599 return D_O_K;
18600 }
18601
18602 const char *globalscriptlist(int32_t index, int32_t *list_size);
18603 12 static ListData globalscript_list(globalscriptlist, &font);
18604 const char *playerscriptlist(int32_t index, int32_t *list_size);
18605 12 static ListData playerscript_list(playerscriptlist, &font);
18606
18607 const char *ffscriptlist(int32_t index, int32_t *list_size);
18608
18609 12 static ListData ffscript_list(ffscriptlist, &font);
18610
18611 char *strip_decimals(char *string)
18612 {
18613 int32_t len=(int32_t)strlen(string);
18614 char *src=(char *)malloc(len+1);
18615 char *tmpsrc=src;
18616 memcpy(src,string,len+1);
18617 memset(src,0,len+1);
18618
18619 for(size_t i=0; string[i]&&i<=strlen(string); i++)
18620 {
18621 *tmpsrc=string[i];
18622
18623 if(*tmpsrc=='.')
18624 {
18625 while(string[i+1]=='.'&&i<=strlen(string))
18626 {
18627 i++;
18628 }
18629 }
18630
18631 tmpsrc++;
18632 }
18633
18634 memcpy(string,src,len);
18635 free(src);
18636 return string;
18637 }
18638
18639 // Unused??? -L 6/6/11
18640 char *clean_numeric_string(char *string)
18641 {
18642 bool found_sign=false;
18643 bool found_decimal=false;
18644 int32_t len=(int32_t)strlen(string);
18645 char *src=(char *)malloc(len+1);
18646 char *tmpsrc=src;
18647 memcpy(src,string,len+1);
18648 memset(src,0,len+1);
18649
18650 // strip out non-numerical characters
18651 for(size_t i=0; string[i]&&i<=strlen(string); i++)
18652 {
18653 *tmpsrc=string[i];
18654
18655 if(*tmpsrc!='.'&&*tmpsrc!='-'&&*tmpsrc!='+'&&!isdigit(*tmpsrc))
18656 {
18657 while(*tmpsrc!='.'&&*tmpsrc!='-'&&*tmpsrc!='+'&&!isdigit(*tmpsrc))
18658 {
18659 i++;
18660 }
18661 }
18662
18663 tmpsrc++;
18664 }
18665
18666 len=(int32_t)strlen(src);
18667 char *src2=(char *)malloc(len+1);
18668 tmpsrc=src2;
18669 memcpy(src,src2,len+1);
18670 memset(src2,0,len+1);
18671
18672 // second purge
18673 for(size_t i=0; src[i]&&i<=strlen(src); i++)
18674 {
18675 *tmpsrc=src[i];
18676
18677 if(*tmpsrc=='-'||*tmpsrc=='+')
18678 {
18679 if(found_sign||found_decimal)
18680 {
18681 while(*tmpsrc=='-'||*tmpsrc=='+')
18682 {
18683 i++;
18684 }
18685 }
18686
18687 found_sign=true;
18688 }
18689
18690 if(*tmpsrc=='.')
18691 {
18692 if(found_decimal)
18693 {
18694 while(*tmpsrc=='.')
18695 {
18696 i++;
18697 }
18698 }
18699
18700 found_decimal=true;
18701 }
18702
18703 tmpsrc++;
18704 }
18705
18706 sprintf(string, "%s", src2);
18707 free(src);
18708 free(src2);
18709 return string;
18710 }
18711
18712 script_struct biglobal[NUMSCRIPTGLOBAL+1]; //global script
18713 int32_t biglobal_cnt = -1;
18714 script_struct biffs[NUMSCRIPTFFC]; //ff script
18715 int32_t biffs_cnt = -1;
18716 script_struct biitems[NUMSCRIPTITEM]; //item script
18717 int32_t biitems_cnt = -1;
18718 script_struct binpcs[NUMSCRIPTGUYS]; //npc script
18719 int32_t binpcs_cnt = -1;
18720
18721 script_struct bilweapons[NUMSCRIPTWEAPONS]; //lweapon script
18722 int32_t bilweapons_cnt = -1;
18723
18724 script_struct bieweapons[NUMSCRIPTWEAPONS]; //eweapon script
18725 int32_t bieweapons_cnt = -1;
18726
18727 script_struct bihero[NUMSCRIPTHERO]; //link script
18728 int32_t bihero_cnt = -1;
18729
18730 script_struct biscreens[NUMSCRIPTSCREEN]; //screen (screendata) script
18731 int32_t biscreens_cnt = -1;
18732
18733 script_struct bidmaps[NUMSCRIPTSDMAP]; //dmap (dmapdata) script
18734 int32_t bidmaps_cnt = -1;
18735
18736 script_struct biditemsprites[NUMSCRIPTSITEMSPRITE]; //dmap (dmapdata) script
18737 int32_t biitemsprites_cnt = -1;
18738
18739 script_struct bidcomboscripts[NUMSCRIPTSCOMBODATA]; //dmap (dmapdata) script
18740 int32_t bidcomboscripts_cnt = -1;
18741 //static char ffscript_str_buf[32];
18742
18743 void build_biglobal_list()
18744 {
18745 biglobal[0].first = "(None)";
18746 biglobal[0].second = -1;
18747 biglobal_cnt = 1;
18748
18749 for(int32_t i = 0; i < NUMSCRIPTGLOBAL; ++i)
18750 {
18751 if(globalmap[i].scriptname.length()==0)
18752 continue;
18753
18754 stringstream ss;
18755 ss << globalmap[i].scriptname << " (" << i << ")"; // The word 'slot' preceding all of the numbers is a bit cluttersome. -L.
18756 biglobal[biglobal_cnt].first = ss.str();
18757 biglobal[biglobal_cnt].second = i;
18758 ++biglobal_cnt;
18759 }
18760
18761 // Blank out the rest of the list
18762 for(int32_t i=biglobal_cnt; i<NUMSCRIPTGLOBAL; ++i)
18763 {
18764 biglobal[i].first="";
18765 biglobal[i].second=-1;
18766 }
18767
18768 //Bubble sort! (doesn't account for gaps between scripts)
18769 for(int32_t i = 0; i < biglobal_cnt - 1; i++)
18770 {
18771 for(int32_t j = i + 1; j < biglobal_cnt; j++)
18772 {
18773 if(stricmp(biglobal[i].first.c_str(),biglobal[j].first.c_str()) > 0 && strcmp(biglobal[j].first.c_str(),""))
18774 zc_swap(biglobal[i],biglobal[j]);
18775 }
18776 }
18777
18778 biglobal_cnt = 0;
18779
18780 for(int32_t i = 0; i < NUMSCRIPTGLOBAL+1; ++i)
18781 if(biglobal[i].first.length() > 0)
18782 biglobal_cnt = i+1;
18783 }
18784
18785 6 void build_biffs_list()
18786 {
18787 6 biffs[0].first = "(None)";
18788 6 biffs[0].second = -1;
18789 6 biffs_cnt = 1;
18790
18791
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(int32_t i = 0; i < NUMSCRIPTFFC - 1; i++)
18792 {
18793
2/2
✓ Branch 0 taken 79 times.
✓ Branch 1 taken 2987 times.
3066 if(ffcmap[i].scriptname.length()==0)
18794 2987 continue;
18795
18796 79 stringstream ss;
18797
5/10
✓ Branch 0 taken 79 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 79 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 79 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 79 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 79 times.
✗ Branch 9 not taken.
79 ss << ffcmap[i].scriptname << " (" << i+1 << ")"; // The word 'slot' preceding all of the numbers is a bit cluttersome. -L.
18798
1/2
✓ Branch 0 taken 79 times.
✗ Branch 1 not taken.
79 biffs[biffs_cnt].first = ss.str();
18799 79 biffs[biffs_cnt].second = i;
18800 79 biffs_cnt++;
18801 79 }
18802
18803 // Blank out the rest of the list
18804
2/2
✓ Branch 0 taken 2987 times.
✓ Branch 1 taken 6 times.
2993 for(int32_t i=biffs_cnt; i<NUMSCRIPTFFC; i++)
18805 {
18806 2987 biffs[i].first="";
18807 2987 biffs[i].second=-1;
18808 2987 }
18809
18810 //Bubble sort! (doesn't account for gaps between scripts)
18811
2/2
✓ Branch 0 taken 79 times.
✓ Branch 1 taken 6 times.
85 for(int32_t i = 0; i < biffs_cnt - 1; i++)
18812 {
18813
2/2
✓ Branch 0 taken 1383 times.
✓ Branch 1 taken 79 times.
1462 for(int32_t j = i + 1; j < biffs_cnt; j++)
18814 {
18815
3/4
✓ Branch 0 taken 540 times.
✓ Branch 1 taken 843 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 540 times.
1383 if(stricmp(biffs[i].first.c_str(),biffs[j].first.c_str()) > 0 && strcmp(biffs[j].first.c_str(),""))
18816 540 zc_swap(biffs[i],biffs[j]);
18817 1383 }
18818 79 }
18819
18820 6 biffs_cnt = 0;
18821
18822
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 6 times.
3078 for(int32_t i = 0; i < NUMSCRIPTFFC; i++)
18823
2/2
✓ Branch 0 taken 2987 times.
✓ Branch 1 taken 85 times.
3157 if(biffs[i].first.length() > 0)
18824 85 biffs_cnt = i+1;
18825 6 }
18826
18827 //npc scripts
18828 void build_binpcs_list()
18829 {
18830 binpcs[0].first = "(None)";
18831 binpcs[0].second = -1;
18832 binpcs_cnt = 1;
18833
18834 for(int32_t i = 0; i < NUMSCRIPTGUYS - 1; i++)
18835 {
18836 if(npcmap[i].scriptname.length()==0)
18837 continue;
18838
18839 stringstream ss;
18840 ss << npcmap[i].scriptname << " (" << i+1 << ")"; // The word 'slot' preceding all of the numbers is a bit cluttersome. -L.
18841 binpcs[binpcs_cnt].first = ss.str();
18842 binpcs[binpcs_cnt].second = i;
18843 binpcs_cnt++;
18844 }
18845
18846 // Blank out the rest of the list
18847 for(int32_t i=binpcs_cnt; i<NUMSCRIPTGUYS; i++)
18848 {
18849 binpcs[i].first="";
18850 binpcs[i].second=-1;
18851 }
18852
18853 //Bubble sort! (doesn't account for gaps between scripts)
18854 for(int32_t i = 0; i < binpcs_cnt - 1; i++)
18855 {
18856 for(int32_t j = i + 1; j < binpcs_cnt; j++)
18857 {
18858 if(stricmp(binpcs[i].first.c_str(),binpcs[j].first.c_str()) > 0 && strcmp(binpcs[j].first.c_str(),""))
18859 zc_swap(binpcs[i],binpcs[j]);
18860 }
18861 }
18862
18863 binpcs_cnt = 0;
18864
18865 for(int32_t i = 0; i < NUMSCRIPTGUYS; i++)
18866 if(binpcs[i].first.length() > 0)
18867 binpcs_cnt = i+1;
18868 }
18869
18870
18871 //lweapon scripts
18872 void build_bilweapons_list()
18873 {
18874 bilweapons[0].first = "(None)";
18875 bilweapons[0].second = -1;
18876 bilweapons_cnt = 1;
18877
18878 for(int32_t i = 0; i < NUMSCRIPTWEAPONS - 1; i++)
18879 {
18880 if(lwpnmap[i].scriptname.length()==0)
18881 continue;
18882
18883 stringstream ss;
18884 ss << lwpnmap[i].scriptname << " (" << i+1 << ")"; // The word 'slot' preceding all of the numbers is a bit cluttersome. -L.
18885 bilweapons[bilweapons_cnt].first = ss.str();
18886 bilweapons[bilweapons_cnt].second = i;
18887 bilweapons_cnt++;
18888 }
18889
18890 // Blank out the rest of the list
18891 for(int32_t i=bilweapons_cnt; i<NUMSCRIPTWEAPONS; i++)
18892 {
18893 bilweapons[i].first="";
18894 bilweapons[i].second=-1;
18895 }
18896
18897 //Bubble sort! (doesn't account for gaps between scripts)
18898 for(int32_t i = 0; i < bilweapons_cnt - 1; i++)
18899 {
18900 for(int32_t j = i + 1; j < bilweapons_cnt; j++)
18901 {
18902 if(stricmp(bilweapons[i].first.c_str(),bilweapons[j].first.c_str()) > 0 && strcmp(bilweapons[j].first.c_str(),""))
18903 zc_swap(bilweapons[i],bilweapons[j]);
18904 }
18905 }
18906
18907 bilweapons_cnt = 0;
18908
18909 for(int32_t i = 0; i < NUMSCRIPTWEAPONS; i++)
18910 if(bilweapons[i].first.length() > 0)
18911 bilweapons_cnt = i+1;
18912 }
18913
18914 //eweapon scripts
18915 void build_bieweapons_list()
18916 {
18917 bieweapons[0].first = "(None)";
18918 bieweapons[0].second = -1;
18919 bieweapons_cnt = 1;
18920
18921 for(int32_t i = 0; i < NUMSCRIPTWEAPONS - 1; i++)
18922 {
18923 if(ewpnmap[i].scriptname.length()==0)
18924 continue;
18925
18926 stringstream ss;
18927 ss << ewpnmap[i].scriptname << " (" << i+1 << ")"; // The word 'slot' preceding all of the numbers is a bit cluttersome. -L.
18928 bieweapons[bieweapons_cnt].first = ss.str();
18929 bieweapons[bieweapons_cnt].second = i;
18930 bieweapons_cnt++;
18931 }
18932
18933 // Blank out the rest of the list
18934 for(int32_t i=bieweapons_cnt; i<NUMSCRIPTWEAPONS; i++)
18935 {
18936 bieweapons[i].first="";
18937 bieweapons[i].second=-1;
18938 }
18939
18940 //Bubble sort! (doesn't account for gaps between scripts)
18941 for(int32_t i = 0; i < bieweapons_cnt - 1; i++)
18942 {
18943 for(int32_t j = i + 1; j < bieweapons_cnt; j++)
18944 {
18945 if(stricmp(bieweapons[i].first.c_str(),bieweapons[j].first.c_str()) > 0 && strcmp(bieweapons[j].first.c_str(),""))
18946 zc_swap(bieweapons[i],bieweapons[j]);
18947 }
18948 }
18949
18950 bieweapons_cnt = 0;
18951
18952 for(int32_t i = 0; i < NUMSCRIPTWEAPONS; i++)
18953 if(bieweapons[i].first.length() > 0)
18954 bieweapons_cnt = i+1;
18955 }
18956
18957 //player scripts
18958 void build_bihero_list()
18959 {
18960 bihero[0].first = "(None)";
18961 bihero[0].second = -1;
18962 bihero_cnt = 1;
18963
18964 for(int32_t i = 0; i < NUMSCRIPTHERO - 1; i++)
18965 {
18966 if(playermap[i].scriptname.length()==0)
18967 continue;
18968
18969 stringstream ss;
18970 ss << playermap[i].scriptname << " (" << i+1 << ")"; // The word 'slot' preceding all of the numbers is a bit cluttersome. -L.
18971 bihero[bihero_cnt].first = ss.str();
18972 bihero[bihero_cnt].second = i;
18973 bihero_cnt++;
18974 }
18975
18976 // Blank out the rest of the list
18977 for(int32_t i=bihero_cnt; i<NUMSCRIPTHERO; i++)
18978 {
18979 bihero[i].first="";
18980 bihero[i].second=-1;
18981 }
18982
18983 //Bubble sort! (doesn't account for gaps between scripts)
18984 for(int32_t i = 0; i < bihero_cnt - 1; i++)
18985 {
18986 for(int32_t j = i + 1; j < bihero_cnt; j++)
18987 {
18988 if(stricmp(bihero[i].first.c_str(),bihero[j].first.c_str()) > 0 && strcmp(bihero[j].first.c_str(),""))
18989 zc_swap(bihero[i],bihero[j]);
18990 }
18991 }
18992
18993 bihero_cnt = 0;
18994
18995 for(int32_t i = 0; i < NUMSCRIPTHERO; i++)
18996 if(bihero[i].first.length() > 0)
18997 bihero_cnt = i+1;
18998 }
18999
19000 //dmap scripts
19001 void build_bidmaps_list()
19002 {
19003 bidmaps[0].first = "(None)";
19004 bidmaps[0].second = -1;
19005 bidmaps_cnt = 1;
19006
19007 for(int32_t i = 0; i < NUMSCRIPTSDMAP - 1; i++)
19008 {
19009 if(dmapmap[i].scriptname.length()==0)
19010 continue;
19011
19012 stringstream ss;
19013 ss << dmapmap[i].scriptname << " (" << i+1 << ")"; // The word 'slot' preceding all of the numbers is a bit cluttersome. -L.
19014 bidmaps[bidmaps_cnt].first = ss.str();
19015 bidmaps[bidmaps_cnt].second = i;
19016 bidmaps_cnt++;
19017 }
19018
19019 // Blank out the rest of the list
19020 for(int32_t i=bidmaps_cnt; i<NUMSCRIPTSDMAP; i++)
19021 {
19022 bidmaps[i].first="";
19023 bidmaps[i].second=-1;
19024 }
19025
19026 //Bubble sort! (doesn't account for gaps between scripts)
19027 for(int32_t i = 0; i < bidmaps_cnt - 1; i++)
19028 {
19029 for(int32_t j = i + 1; j < bidmaps_cnt; j++)
19030 {
19031 if(stricmp(bidmaps[i].first.c_str(),bidmaps[j].first.c_str()) > 0 && strcmp(bidmaps[j].first.c_str(),""))
19032 zc_swap(bidmaps[i],bidmaps[j]);
19033 }
19034 }
19035
19036 bidmaps_cnt = 0;
19037
19038 for(int32_t i = 0; i < NUMSCRIPTSDMAP; i++)
19039 if(bidmaps[i].first.length() > 0)
19040 bidmaps_cnt = i+1;
19041 }
19042
19043 //screen scripts
19044 void build_biscreens_list()
19045 {
19046 biscreens[0].first = "(None)";
19047 biscreens[0].second = -1;
19048 biscreens_cnt = 1;
19049
19050 for(int32_t i = 0; i < NUMSCRIPTSCREEN - 1; i++)
19051 {
19052 if(screenmap[i].scriptname.length()==0)
19053 continue;
19054
19055 stringstream ss;
19056 ss << screenmap[i].scriptname << " (" << i+1 << ")"; // The word 'slot' preceding all of the numbers is a bit cluttersome. -L.
19057 biscreens[biscreens_cnt].first = ss.str();
19058 biscreens[biscreens_cnt].second = i;
19059 biscreens_cnt++;
19060 }
19061
19062 // Blank out the rest of the list
19063 for(int32_t i=biscreens_cnt; i<NUMSCRIPTSCREEN; i++)
19064 {
19065 biscreens[i].first="";
19066 biscreens[i].second=-1;
19067 }
19068
19069 //Bubble sort! (doesn't account for gaps between scripts)
19070 for(int32_t i = 0; i < biscreens_cnt - 1; i++)
19071 {
19072 for(int32_t j = i + 1; j < biscreens_cnt; j++)
19073 {
19074 if(stricmp(biscreens[i].first.c_str(),biscreens[j].first.c_str()) > 0 && strcmp(biscreens[j].first.c_str(),""))
19075 zc_swap(biscreens[i],biscreens[j]);
19076 }
19077 }
19078
19079 biscreens_cnt = 0;
19080
19081 for(int32_t i = 0; i < NUMSCRIPTSCREEN; i++)
19082 if(biscreens[i].first.length() > 0)
19083 biscreens_cnt = i+1;
19084 }
19085
19086 //screen scripts
19087 void build_biitemsprites_list()
19088 {
19089 biditemsprites[0].first = "(None)";
19090 biditemsprites[0].second = -1;
19091 biitemsprites_cnt = 1;
19092
19093 for(int32_t i = 0; i < NUMSCRIPTSITEMSPRITE - 1; i++)
19094 {
19095 if(itemspritemap[i].scriptname.length()==0)
19096 continue;
19097
19098 stringstream ss;
19099 ss << itemspritemap[i].scriptname << " (" << i+1 << ")"; // The word 'slot' preceding all of the numbers is a bit cluttersome. -L.
19100 biditemsprites[biitemsprites_cnt].first = ss.str();
19101 biditemsprites[biitemsprites_cnt].second = i;
19102 biitemsprites_cnt++;
19103 }
19104
19105 // Blank out the rest of the list
19106 for(int32_t i=biitemsprites_cnt; i<NUMSCRIPTSITEMSPRITE; i++)
19107 {
19108 biditemsprites[i].first="";
19109 biditemsprites[i].second=-1;
19110 }
19111
19112 //Bubble sort! (doesn't account for gaps between scripts)
19113 for(int32_t i = 0; i < biitemsprites_cnt - 1; i++)
19114 {
19115 for(int32_t j = i + 1; j < biitemsprites_cnt; j++)
19116 {
19117 if(stricmp(biditemsprites[i].first.c_str(),biditemsprites[j].first.c_str()) > 0 && strcmp(biditemsprites[j].first.c_str(),""))
19118 zc_swap(biditemsprites[i],biditemsprites[j]);
19119 }
19120 }
19121
19122 biitemsprites_cnt = 0;
19123
19124 for(int32_t i = 0; i < NUMSCRIPTSITEMSPRITE; i++)
19125 if(biditemsprites[i].first.length() > 0)
19126 biitemsprites_cnt = i+1;
19127 }
19128
19129 6 void build_biitems_list()
19130 {
19131 6 biitems[0].first = "(None)";
19132 6 biitems[0].second = -1;
19133 6 biitems_cnt = 1;
19134
19135
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(int32_t i = 0; i < NUMSCRIPTITEM - 1; i++, biitems_cnt++)
19136 {
19137 1530 stringstream ss;
19138
19139
4/6
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1530 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 13 times.
✓ Branch 5 taken 1517 times.
1530 if(!itemmap[i].isEmpty())
19140
5/10
✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 13 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 13 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 13 times.
✗ Branch 9 not taken.
13 ss << itemmap[i].scriptname << " (" << i+1 << ")";
19141
19142
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 biitems[biitems_cnt].first = ss.str();
19143 1530 biitems[biitems_cnt].second = i;
19144 1530 }
19145
19146
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(int32_t i = 0; i < biitems_cnt - 1; i++)
19147 {
19148
2/2
✓ Branch 0 taken 195840 times.
✓ Branch 1 taken 1530 times.
197370 for(int32_t j = i + 1; j < biitems_cnt; j++)
19149 {
19150
4/4
✓ Branch 0 taken 4760 times.
✓ Branch 1 taken 191080 times.
✓ Branch 2 taken 4757 times.
✓ Branch 3 taken 3 times.
195840 if(stricmp(biitems[i].first.c_str(), biitems[j].first.c_str()) > 0 && strcmp(biitems[j].first.c_str(),""))
19151 3 zc_swap(biitems[i], biitems[j]);
19152 195840 }
19153 1530 }
19154
19155 6 biitems_cnt = 0;
19156
19157
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i = 0; i < NUMSCRIPTITEM; i++)
19158
2/2
✓ Branch 0 taken 1517 times.
✓ Branch 1 taken 19 times.
1555 if(biitems[i].first.length() > 0)
19159 19 biitems_cnt = i+1;
19160 6 }
19161
19162
19163 //dmap scripts
19164 void build_bidcomboscripts_list()
19165 {
19166 bidcomboscripts[0].first = "(None)";
19167 bidcomboscripts[0].second = -1;
19168 bidcomboscripts_cnt = 1;
19169
19170 for(int32_t i = 0; i < NUMSCRIPTSCOMBODATA - 1; i++)
19171 {
19172 if(comboscriptmap[i].scriptname.length()==0)
19173 continue;
19174
19175 stringstream ss;
19176 ss << comboscriptmap[i].scriptname << " (" << i+1 << ")"; // The word 'slot' preceding all of the numbers is a bit cluttersome. -L.
19177 bidcomboscripts[bidcomboscripts_cnt].first = ss.str();
19178 bidcomboscripts[bidcomboscripts_cnt].second = i;
19179 bidcomboscripts_cnt++;
19180 }
19181
19182 // Blank out the rest of the list
19183 for(int32_t i=bidcomboscripts_cnt; i<NUMSCRIPTSCOMBODATA; i++)
19184 {
19185 bidcomboscripts[i].first="";
19186 bidcomboscripts[i].second=-1;
19187 }
19188
19189 //Bubble sort! (doesn't account for gaps between scripts)
19190 for(int32_t i = 0; i < bidcomboscripts_cnt - 1; i++)
19191 {
19192 for(int32_t j = i + 1; j < bidcomboscripts_cnt; j++)
19193 {
19194 if(stricmp(bidcomboscripts[i].first.c_str(),bidcomboscripts[j].first.c_str()) > 0 && strcmp(bidcomboscripts[j].first.c_str(),""))
19195 zc_swap(bidcomboscripts[i],bidcomboscripts[j]);
19196 }
19197 }
19198
19199 bidcomboscripts_cnt = 0;
19200
19201 for(int32_t i = 0; i < NUMSCRIPTSCOMBODATA; i++)
19202 if(bidcomboscripts[i].first.length() > 0)
19203 bidcomboscripts_cnt = i+1;
19204 }
19205
19206
19207 const char *globalscriptlist(int32_t index, int32_t *list_size)
19208 {
19209 if(index < 0)
19210 {
19211 *list_size = biglobal_cnt;
19212 return NULL;
19213 }
19214
19215 return biglobal[index].first.c_str();
19216 }
19217
19218 const char *ffscriptlist(int32_t index, int32_t *list_size)
19219 {
19220 if(index < 0)
19221 {
19222 *list_size = biffs_cnt;
19223 return NULL;
19224 }
19225
19226 return biffs[index].first.c_str();
19227 }
19228
19229 const char *playerscriptlist(int32_t index, int32_t *list_size)
19230 {
19231 if(index < 0)
19232 {
19233 *list_size = bihero_cnt;
19234 return NULL;
19235 }
19236
19237 return bihero[index].first.c_str();
19238 }
19239
19240 const char *lweaponscriptlist(int32_t index, int32_t *list_size)
19241 {
19242 if(index < 0)
19243 {
19244 *list_size = bilweapons_cnt;
19245 return NULL;
19246 }
19247
19248 return bilweapons[index].first.c_str();
19249 }
19250
19251 const char *npcscriptlist(int32_t index, int32_t *list_size)
19252 {
19253 if(index < 0)
19254 {
19255 *list_size = binpcs_cnt;
19256 return NULL;
19257 }
19258
19259 return binpcs[index].first.c_str();
19260 }
19261
19262 static char itemscript_str_buf[32];
19263
19264 char *itemscriptlist(int32_t index, int32_t *list_size)
19265 {
19266 if(index>=0)
19267 {
19268 bound(index,0,255);
19269 sprintf(itemscript_str_buf,"%d: %s",index, ffcmap[index-1].scriptname.c_str());
19270 return itemscript_str_buf;
19271 }
19272
19273 *list_size=256;
19274 return NULL;
19275 }
19276
19277 static char ffscript_str_buf2[32];
19278
19279 const char *ffscriptlist2(int32_t index, int32_t *list_size)
19280 {
19281 if(index>=0)
19282 {
19283 char buf[20];
19284 bound(index,0,510);
19285
19286 if(ffcmap[index].scriptname=="")
19287 strcpy(buf, "<none>");
19288 else
19289 {
19290 strncpy(buf, ffcmap[index].scriptname.c_str(), 19);
19291 buf[19]='\0';
19292 }
19293
19294 sprintf(ffscript_str_buf2,"%d: %s",index+1, buf);
19295 return ffscript_str_buf2;
19296 }
19297
19298 *list_size=511;
19299 return NULL;
19300 }
19301
19302 static char itemscript_str_buf2[32];
19303
19304 const char *itemscriptlist2(int32_t index, int32_t *list_size)
19305 {
19306 if(index>=0)
19307 {
19308 char buf[20];
19309 bound(index,0,254);
19310
19311 if(itemmap[index].scriptname=="")
19312 strcpy(buf, "<none>");
19313 else
19314 {
19315 strncpy(buf, itemmap[index].scriptname.c_str(), 19);
19316 buf[19]='\0';
19317 }
19318
19319 sprintf(itemscript_str_buf2,"%d: %s",index+1, buf);
19320 return itemscript_str_buf2;
19321 }
19322
19323 *list_size=255;
19324 return NULL;
19325 }
19326
19327
19328 static char comboscript_str_buf2[32];
19329 const char *comboscriptlist2(int32_t index, int32_t *list_size)
19330 {
19331 if(index>=0)
19332 {
19333 char buf[20];
19334 bound(index,0,254);
19335
19336 if(comboscriptmap[index].scriptname=="")
19337 strcpy(buf, "<none>");
19338 else
19339 {
19340 strncpy(buf, comboscriptmap[index].scriptname.c_str(), 19);
19341 buf[19]='\0';
19342 }
19343
19344 sprintf(comboscript_str_buf2,"%d: %s",index+1, buf);
19345 return comboscript_str_buf2;
19346 }
19347
19348 *list_size=255;
19349 return NULL;
19350 }
19351
19352 static char gscript_str_buf2[40];
19353
19354 const char *gscriptlist2(int32_t index, int32_t *list_size)
19355 {
19356 if(index >= 0)
19357 {
19358 bound(index,0,3);
19359
19360 char buf[20];
19361
19362 if(globalmap[index].scriptname == "")
19363 strcpy(buf, "<none>");
19364 else
19365 {
19366 strncpy(buf, globalmap[index].scriptname.c_str(), 19);
19367 buf[19]='\0';
19368 }
19369
19370 switch(index)
19371 {
19372 case GLOBAL_SCRIPT_INIT:
19373 sprintf(gscript_str_buf2,"Initialization: %s", buf); break;
19374 case GLOBAL_SCRIPT_GAME:
19375 sprintf(gscript_str_buf2,"Active: %s", buf); break;
19376 case GLOBAL_SCRIPT_END:
19377 sprintf(gscript_str_buf2,"onExit: %s", buf); break;
19378 case GLOBAL_SCRIPT_ONSAVELOAD:
19379 sprintf(gscript_str_buf2,"onSaveLoad: %s", buf); break;
19380 case GLOBAL_SCRIPT_ONLAUNCH:
19381 sprintf(gscript_str_buf2,"onLaunch: %s", buf); break;
19382 case GLOBAL_SCRIPT_ONCONTGAME:
19383 sprintf(gscript_str_buf2,"onContGame: %s", buf); break;
19384 case GLOBAL_SCRIPT_F6:
19385 sprintf(gscript_str_buf2,"onF6Menu: %s", buf); break;
19386 case GLOBAL_SCRIPT_ONSAVE:
19387 sprintf(gscript_str_buf2,"onSave: %s", buf); break;
19388 }
19389
19390 return gscript_str_buf2;
19391 }
19392
19393 if(list_size != NULL)
19394 *list_size=4;
19395
19396 return NULL;
19397 }
19398
19399 static int32_t as_ffc_list[] = { 4, 5, 6, -1};
19400 static int32_t as_global_list[] = { 7, 8, 9, -1}; //Why does putting 15 in here not place my message only on the global tab? ~Joe
19401 static int32_t as_item_list[] = { 10, 11, 12, -1};
19402 static int32_t as_npc_list[] = { 18, 19, 20, -1}; //npc scripts TAB
19403 static int32_t as_lweapon_list[] = { 21, 22, 23, -1}; //lweapon scripts TAB
19404 static int32_t as_eweapon_list[] = { 24, 25, 26, -1}; //eweapon scripts TAB
19405 static int32_t as_hero_list[] = { 27, 28, 29, -1}; //hero scripts TAB
19406 static int32_t as_screen_list[] = { 30, 31, 32, -1}; //screendata scripts TAB
19407 static int32_t as_dmap_list[] = { 33, 34, 35, -1}; //dmapdata scripts TAB
19408 static int32_t as_itemsprite_list[] = { 36, 37, 38, -1}; //dmapdata scripts TAB
19409 static int32_t as_comboscript_list[] = { 39, 40, 41, -1}; //combodata scripts TAB
19410 static int32_t as_genericscript_list[] = { 45, 46, 47, -1}; //generic scripts TAB
19411 static int32_t as_subscreenscript_list[] = { 48, 49, 50, -1}; //generic scripts TAB
19412
19413 static TABPANEL assignscript_tabs[] =
19414 {
19415 // (text)
19416 { (char *)"FFC", D_SELECTED, as_ffc_list, 0, NULL },
19417 { (char *)"Global", 0, as_global_list, 0, NULL },
19418 { (char *)"Item", 0, as_item_list, 0, NULL },
19419 { (char *)"NPC", 0, as_npc_list, 0, NULL },
19420 { (char *)"LWeapon", 0, as_lweapon_list, 0, NULL },
19421 { (char *)"EWeapon", 0, as_eweapon_list, 0, NULL },
19422 { (char *)"Hero", 0, as_hero_list, 0, NULL },
19423 { (char *)"DMap", 0, as_dmap_list, 0, NULL },
19424 { (char *)"Screen", 0, as_screen_list, 0, NULL },
19425 { (char *)"Item Sprite", 0, as_itemsprite_list, 0, NULL },
19426 { (char *)"Combo", 0, as_comboscript_list, 0, NULL },
19427 { (char *)"Generic", 0, as_genericscript_list, 0, NULL },
19428 { (char *)"Subscreen", 0, as_subscreenscript_list, 0, NULL },
19429 { NULL, 0, NULL, 0, NULL }
19430 };
19431
19432 const char *assignffclist(int32_t index, int32_t *list_size)
19433 {
19434 if(index<0)
19435 {
19436 *list_size = (int32_t)ffcmap.size();
19437 return NULL;
19438 }
19439
19440 return ffcmap[index].output.c_str();
19441 }
19442
19443 const char *assigngloballist(int32_t index, int32_t *list_size)
19444 {
19445 if(index<0)
19446 {
19447 *list_size = (int32_t)globalmap.size();
19448 return NULL;
19449 }
19450
19451 return globalmap[index].output.c_str();
19452 }
19453
19454 const char *assigncombolist(int32_t index, int32_t *list_size)
19455 {
19456 if(index<0)
19457 {
19458 *list_size = (int32_t)comboscriptmap.size();
19459 return NULL;
19460 }
19461
19462 return comboscriptmap[index].output.c_str();
19463 }
19464
19465 const char *assigngenericlist(int32_t index, int32_t *list_size)
19466 {
19467 if(index<0)
19468 {
19469 *list_size = ((int32_t)genericmap.size());
19470 return NULL;
19471 }
19472
19473 return genericmap[index].output.c_str();
19474 }
19475
19476 const char *assignsubscreenlist(int32_t index, int32_t *list_size)
19477 {
19478 if(index<0)
19479 {
19480 *list_size = ((int32_t)subscreenmap.size());
19481 return NULL;
19482 }
19483
19484 return subscreenmap[index].output.c_str();
19485 }
19486
19487 const char *assignitemlist(int32_t index, int32_t *list_size)
19488 {
19489 if(index<0)
19490 {
19491 *list_size = (int32_t)itemmap.size();
19492 return NULL;
19493 }
19494
19495 return itemmap[index].output.c_str();
19496 }
19497 const char *assignnpclist(int32_t index, int32_t *list_size)
19498 {
19499 if(index<0)
19500 {
19501 *list_size = (int32_t)npcmap.size();
19502 return NULL;
19503 }
19504
19505 return npcmap[index].output.c_str();
19506 }
19507
19508 const char *assignlweaponlist(int32_t index, int32_t *list_size)
19509 {
19510 if(index<0)
19511 {
19512 *list_size = (int32_t)lwpnmap.size();
19513 return NULL;
19514 }
19515
19516 return lwpnmap[index].output.c_str();
19517 }
19518
19519 const char *assigneweaponlist(int32_t index, int32_t *list_size)
19520 {
19521 if(index<0)
19522 {
19523 *list_size = (int32_t)ewpnmap.size();
19524 return NULL;
19525 }
19526
19527 return ewpnmap[index].output.c_str();
19528 }
19529
19530 const char *assignplayerlist(int32_t index, int32_t *list_size)
19531 {
19532 if(index<0)
19533 {
19534 *list_size = (int32_t)playermap.size();
19535 return NULL;
19536 }
19537
19538 return playermap[index].output.c_str();
19539 }
19540
19541 const char *assigndmaplist(int32_t index, int32_t *list_size)
19542 {
19543 if(index<0)
19544 {
19545 *list_size = (int32_t)dmapmap.size();
19546 return NULL;
19547 }
19548
19549 return dmapmap[index].output.c_str();
19550 }
19551
19552 const char *assignscreenlist(int32_t index, int32_t *list_size)
19553 {
19554 if(index<0)
19555 {
19556 *list_size = (int32_t)screenmap.size();
19557 return NULL;
19558 }
19559
19560 return screenmap[index].output.c_str();
19561 }
19562
19563 const char *assignitemspritelist(int32_t index, int32_t *list_size)
19564 {
19565 if(index<0)
19566 {
19567 *list_size = (int32_t)itemspritemap.size();
19568 return NULL;
19569 }
19570
19571 return itemspritemap[index].output.c_str();
19572 }
19573
19574 const char *assignffcscriptlist(int32_t index, int32_t *list_size)
19575 {
19576 if(index<0)
19577 {
19578 *list_size = (int32_t)asffcscripts.size();
19579 return NULL;
19580 }
19581
19582 return asffcscripts[index].c_str();
19583 }
19584
19585 const char *assignglobalscriptlist(int32_t index, int32_t *list_size)
19586 {
19587 if(index<0)
19588 {
19589 *list_size = (int32_t)asglobalscripts.size();
19590 return NULL;
19591 }
19592
19593 return asglobalscripts[index].c_str();
19594 }
19595
19596 const char *assignitemscriptlist(int32_t index, int32_t *list_size)
19597 {
19598 if(index<0)
19599 {
19600 *list_size = (int32_t)asitemscripts.size();
19601 return NULL;
19602 }
19603
19604 return asitemscripts[index].c_str();
19605 }
19606
19607 const char *assignnpcscriptlist(int32_t index, int32_t *list_size)
19608 {
19609 if(index<0)
19610 {
19611 *list_size = (int32_t)asnpcscripts.size();
19612 return NULL;
19613 }
19614
19615 return asnpcscripts[index].c_str();
19616 }
19617
19618 const char *assignlweaponscriptlist(int32_t index, int32_t *list_size)
19619 {
19620 if(index<0)
19621 {
19622 *list_size = (int32_t)aslweaponscripts.size();
19623 return NULL;
19624 }
19625
19626 return aslweaponscripts[index].c_str();
19627 }
19628
19629 const char *assigneweaponscriptlist(int32_t index, int32_t *list_size)
19630 {
19631 if(index<0)
19632 {
19633 *list_size = (int32_t)aseweaponscripts.size();
19634 return NULL;
19635 }
19636
19637 return aseweaponscripts[index].c_str();
19638 }
19639
19640 const char *assignplayerscriptlist(int32_t index, int32_t *list_size)
19641 {
19642 if(index<0)
19643 {
19644 *list_size = (int32_t)asplayerscripts.size();
19645 return NULL;
19646 }
19647
19648 return asplayerscripts[index].c_str();
19649 }
19650
19651 const char *assigndmapscriptlist(int32_t index, int32_t *list_size)
19652 {
19653 if(index<0)
19654 {
19655 *list_size = (int32_t)asdmapscripts.size();
19656 return NULL;
19657 }
19658
19659 return asdmapscripts[index].c_str();
19660 }
19661
19662 const char *assignscreenscriptlist(int32_t index, int32_t *list_size)
19663 {
19664 if(index<0)
19665 {
19666 *list_size = (int32_t)asscreenscripts.size();
19667 return NULL;
19668 }
19669
19670 return asscreenscripts[index].c_str();
19671 }
19672
19673 const char *assignitemspritescriptlist(int32_t index, int32_t *list_size)
19674 {
19675 if(index<0)
19676 {
19677 *list_size = (int32_t)asitemspritescripts.size();
19678 return NULL;
19679 }
19680
19681 return asitemspritescripts[index].c_str();
19682 }
19683
19684 const char *assigncomboscriptlist(int32_t index, int32_t *list_size)
19685 {
19686 if(index<0)
19687 {
19688 *list_size = (int32_t)ascomboscripts.size();
19689 return NULL;
19690 }
19691
19692 return ascomboscripts[index].c_str();
19693 }
19694
19695 const char *assigngenericscriptlist(int32_t index, int32_t *list_size)
19696 {
19697 if(index<0)
19698 {
19699 *list_size = (int32_t)asgenericscripts.size();
19700 return NULL;
19701 }
19702
19703 return asgenericscripts[index].c_str();
19704 }
19705
19706 const char *assignsubscreenscriptlist(int32_t index, int32_t *list_size)
19707 {
19708 if(index<0)
19709 {
19710 *list_size = (int32_t)assubscreenscripts.size();
19711 return NULL;
19712 }
19713
19714 return assubscreenscripts[index].c_str();
19715 }
19716
19717 12 static ListData assignffc_list(assignffclist, &font);
19718 12 static ListData assignffcscript_list(assignffcscriptlist, &font);
19719 12 static ListData assignglobal_list(assigngloballist, &font);
19720 12 static ListData assignglobalscript_list(assignglobalscriptlist, &font);
19721 12 static ListData assignitem_list(assignitemlist, &font);
19722 12 static ListData assignitemscript_list(assignitemscriptlist, &font);
19723 12 static ListData assignnpc_list(assignnpclist, &font);
19724 12 static ListData assignnpcscript_list(assignnpcscriptlist, &font);
19725 12 static ListData assignlweapon_list(assignlweaponlist, &font);
19726 12 static ListData assignlweaponscript_list(assignlweaponscriptlist, &font);
19727 12 static ListData assigneweapon_list(assigneweaponlist, &font);
19728 12 static ListData assigneweaponscript_list(assigneweaponscriptlist, &font);
19729
19730 12 static ListData assignplayer_list(assignplayerlist, &font);
19731 12 static ListData assignplayerscript_list(assignplayerscriptlist, &font);
19732
19733 12 static ListData assigndmap_list(assigndmaplist, &font);
19734 12 static ListData assigndmapscript_list(assigndmapscriptlist, &font);
19735
19736 12 static ListData assignscreen_list(assignscreenlist, &font);
19737 12 static ListData assignscreenscript_list(assignscreenscriptlist, &font);
19738
19739 12 static ListData assignitemsprite_list(assignitemspritelist, &font);
19740 12 static ListData assignitemspritescript_list(assignitemspritescriptlist, &font);
19741
19742 12 static ListData assigncombo_list(assigncombolist, &font);
19743 12 static ListData assigncomboscript_list(assigncomboscriptlist, &font);
19744
19745 12 static ListData assigngeneric_list(assigngenericlist, &font);
19746 12 static ListData assigngenericscript_list(assigngenericscriptlist, &font);
19747
19748 12 static ListData assignsubscreen_list(assignsubscreenlist, &font);
19749 12 static ListData assignsubscreenscript_list(assignsubscreenscriptlist, &font);
19750
19751 static DIALOG assignscript_dlg[] =
19752 {
19753 // x y w h fg bg key flags d1 d2 dp
19754 12 { jwin_win_proc, 0, 0, 330, 236, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Assign Compiled Script", NULL, NULL },
19755 12 { jwin_tab_proc, 6, 25, 330-12, 130, 0, 0, 0, 0, 0, 0, assignscript_tabs, NULL, (void*)assignscript_dlg },
19756 12 { jwin_button_proc, 251, 207, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
19757 12 { jwin_button_proc, 182, 207, 61, 21, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
19758 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignffc_list, NULL, NULL },
19759 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignffcscript_list, NULL, NULL },
19760 //6
19761 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19762 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignglobal_list, NULL, NULL },
19763 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignglobalscript_list, NULL, NULL },
19764 //9
19765 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19766 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignitem_list, NULL, NULL },
19767 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignitemscript_list, NULL, NULL },
19768 //12
19769 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19770 //13
19771 12 { jwin_check_proc, 22, 211, 90, 8, vc(14), vc(1), 0, 0, 1, 0, (void *) "Output ZASM code to allegro.log", NULL, NULL },
19772 12 { jwin_text_proc, 22, 178, 90, 24, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
19773 12 { d_dummy_proc, 0, 0, 0, 0, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
19774 //16
19775 12 { d_dummy_proc, 0, 0, 0, 0, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
19776 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
19777 //npc scripts
19778 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignnpc_list, NULL, NULL },
19779 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignnpcscript_list, NULL, NULL },
19780 //20
19781 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19782 //21
19783 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignlweapon_list, NULL, NULL },
19784 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignlweaponscript_list, NULL, NULL },
19785 //23
19786 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19787 //24
19788 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assigneweapon_list, NULL, NULL },
19789 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assigneweaponscript_list, NULL, NULL },
19790 //26
19791 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19792 //27
19793 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignplayer_list, NULL, NULL },
19794 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignplayerscript_list, NULL, NULL },
19795 //29
19796 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19797 //30
19798 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignscreen_list, NULL, NULL },
19799 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignscreenscript_list, NULL, NULL },
19800 //32
19801 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19802 //33
19803 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assigndmap_list, NULL, NULL },
19804 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assigndmapscript_list, NULL, NULL },
19805 //35
19806 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19807 //36
19808 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignitemsprite_list, NULL, NULL },
19809 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignitemspritescript_list, NULL, NULL },
19810 //38
19811 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19812
19813 //39
19814 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assigncombo_list, NULL, NULL },
19815 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assigncomboscript_list, NULL, NULL },
19816 //41
19817 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19818 12 { jwin_button_proc, 78-24, 158, 48, 16, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Script Info", NULL, NULL },
19819 12 { jwin_button_proc, 174+78-24, 158, 48, 16, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Script Info", NULL, NULL },
19820 12 { jwin_button_proc, 87+78-24, 158, 48, 16, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Clear", NULL, NULL },
19821 //45
19822 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assigngeneric_list, NULL, NULL },
19823 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assigngenericscript_list, NULL, NULL },
19824 //47
19825 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19826 //48
19827 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignsubscreen_list, NULL, NULL },
19828 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignsubscreenscript_list, NULL, NULL },
19829 //50
19830 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19831 12 { jwin_check_proc, 22, 221, 90, 8, vc(14), vc(1), 0, 0, 1, 0, (void *) "...And output ZASM comments", NULL, NULL },
19832
19833 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
19834
19835 };
19836
19837 int32_t txtout(BITMAP* dest, const char* txt, int32_t x, int32_t y, bool disabled)
19838 {
19839 if(disabled)
19840 {
19841 gui_textout_ln(dest, font, (uint8_t*)txt, x+1, y+1, scheme[jcLIGHT], scheme[jcBOX], 0);
19842 return gui_textout_ln(dest, font, (uint8_t*)txt, x, y, scheme[jcMEDDARK], -1, 0);
19843 }
19844 else
19845 {
19846 return gui_textout_ln(dest, font, (uint8_t*)txt, x, y, scheme[jcBOXFG], scheme[jcBOX], 0);
19847 }
19848 }
19849
19850 int32_t jwin_zmeta_proc(int32_t msg, DIALOG *d, int32_t )
19851 {
19852 int32_t ret = D_O_K;
19853 ASSERT(d);
19854
19855 BITMAP* target = (msg==MSG_START ? NULL : screen);
19856 switch(msg)
19857 {
19858 case MSG_START:
19859 case MSG_DRAW:
19860 {
19861 FONT *oldfont = font;
19862
19863 if(d->dp2)
19864 {
19865 font = (FONT*)d->dp2;
19866 }
19867
19868 bool disabled = (d->flags & D_DISABLED) != 0;
19869 if(d->dp)
19870 {
19871 zasm_meta const& meta = *((zasm_meta*)d->dp);
19872 int32_t ind = -1;
19873 d->w = 0;
19874 if(!meta.valid())
19875 {
19876 d->w = txtout(target, "Invalid ZASM metadata found!", d->x, d->y, disabled);
19877 ++ind;
19878 }
19879
19880 int32_t t_w = 0;
19881 char buf[1024];
19882 memset(buf, 0, sizeof(buf));
19883 sprintf(buf, "ZASM Version: %d", meta.zasm_v);
19884 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
19885 d->w = zc_max(d->w, t_w);
19886 memset(buf, 0, sizeof(buf));
19887 sprintf(buf, "Metadata Version: %d", meta.meta_v);
19888 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
19889 d->w = zc_max(d->w, t_w);
19890 memset(buf, 0, sizeof(buf));
19891 sprintf(buf, "FFScript Version: %d", meta.ffscript_v);
19892 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
19893 d->w = zc_max(d->w, t_w);
19894 memset(buf, 0, sizeof(buf));
19895 sprintf(buf, "Script Name: %s", meta.script_name.c_str());
19896 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
19897 d->w = zc_max(d->w, t_w);
19898 memset(buf, 0, sizeof(buf));
19899 sprintf(buf, "Author: %s", meta.author.c_str());
19900 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
19901 d->w = zc_max(d->w, t_w);
19902 memset(buf, 0, sizeof(buf));
19903 sprintf(buf, "Script Type: %s", get_script_name(meta.script_type).c_str());
19904 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
19905 d->w = zc_max(d->w, t_w);
19906 for(auto q = 0; q < 4; ++q)
19907 {
19908 if(!meta.attributes[q].size())
19909 continue;
19910 memset(buf, 0, sizeof(buf));
19911 sprintf(buf, "Attributes[%d]: %s", q, meta.attributes[q].c_str());
19912 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
19913 d->w = zc_max(d->w, t_w);
19914 }
19915 for(auto q = 0; q < 8; ++q)
19916 {
19917 if(!meta.attribytes[q].size())
19918 continue;
19919 memset(buf, 0, sizeof(buf));
19920 sprintf(buf, "Attribytes[%d]: %s", q, meta.attribytes[q].c_str());
19921 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
19922 d->w = zc_max(d->w, t_w);
19923 }
19924 for(auto q = 0; q < 8; ++q)
19925 {
19926 if(!meta.attrishorts[q].size())
19927 continue;
19928 memset(buf, 0, sizeof(buf));
19929 sprintf(buf, "Attrishorts[%d]: %s", q, meta.attrishorts[q].c_str());
19930 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
19931 d->w = zc_max(d->w, t_w);
19932 }
19933 bool indentrun = false;
19934 int32_t run_indent = txtout(NULL, "void run(", 0, 0, false);
19935 std::ostringstream oss;
19936 oss << "void run(";
19937 for(int32_t q = 0; q < 8; ++q)
19938 {
19939 if(!meta.run_idens[q].size() || meta.run_types[q] == ZMETA_NULL_TYPE) continue;
19940 if(q > 0)
19941 oss << ", ";
19942 string type_name = ZScript::getDataTypeName(meta.run_types[q]);
19943 lowerstr(type_name); //all lowercase for this output
19944 if(oss.str().size() > unsigned(indentrun ? 41 : 50))
19945 {
19946 memset(buf, 0, sizeof(buf));
19947 sprintf(buf, "%s", oss.str().c_str());
19948 t_w = txtout(target, buf, d->x + (indentrun ? run_indent : 0), d->y + ((++ind)*(text_height(font) + 3)), disabled) + (indentrun ? run_indent : 0);
19949 d->w = zc_max(d->w, t_w);
19950 oss.str("");
19951 indentrun = true;
19952 }
19953 oss << type_name.c_str() << " " << meta.run_idens[q];
19954 }
19955 oss << ");";
19956 memset(buf, 0, sizeof(buf));
19957 sprintf(buf, "%s", oss.str().c_str());
19958 t_w = txtout(target, buf, d->x + (indentrun ? run_indent : 0), d->y + ((++ind)*(text_height(font) + 3)), disabled) + (indentrun ? run_indent : 0);
19959 d->w = zc_max(d->w, t_w);
19960 memset(buf, 0, sizeof(buf));
19961 sprintf(buf, "Compiler Version: %d.%d.%d.%d", meta.compiler_v1, meta.compiler_v2, meta.compiler_v3, meta.compiler_v4);
19962 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
19963 d->w = zc_max(d->w, t_w);
19964 memset(buf, 0, sizeof(buf));
19965 sprintf(buf, "Parser-generated: %s", (meta.flags & ZMETA_AUTOGEN)!=0 ? "TRUE" : "FALSE");
19966 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
19967 d->w = zc_max(d->w, t_w);
19968 d->h = (++ind) * (text_height(font) + 3) -3;
19969 }
19970 else
19971 {
19972 d->w = txtout(target, "No ZASM metadata found!", d->x, d->y, disabled);
19973 d->h = text_height(font);
19974 }
19975
19976 if(d->dp3) //function trigger
19977 {
19978 typedef void (*funcType)(void);
19979 funcType func=reinterpret_cast<funcType>(d->dp3);
19980 func();
19981 }
19982
19983 font = oldfont;
19984 break;
19985 }
19986 }
19987
19988 return ret;
19989 }
19990
19991 void resize_scriptinfo_dlg();
19992
19993 static DIALOG scriptinfo_dlg[] =
19994 {
19995 // x y w h fg bg key flags d1 d2 dp
19996 { jwin_win_proc, 0, 0, 200, 150, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Script Metadata", NULL, NULL },
19997 { d_dummy_proc, 6, 25, 330-12, 130, 0, 0, 0, 0, 0, 0, assignscript_tabs, NULL, NULL },
19998 { jwin_button_proc, 70, 120, 60, 20, vc(14), vc(1), 'k', D_EXIT, 0, 0, (void *) "Done", NULL, NULL },
19999 { jwin_zmeta_proc, 50, 30, 100, 100, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, (void*)resize_scriptinfo_dlg },
20000
20001 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
20002 };
20003
20004 void resize_scriptinfo_dlg()
20005 {
20006 DIALOG *meta_proc = &scriptinfo_dlg[3], *window = &scriptinfo_dlg[0], *ok_button = &scriptinfo_dlg[2];
20007 int32_t bmargin = 15, hmargins = 30;
20008 jwin_ulalign_dialog(scriptinfo_dlg);
20009 window->w = hmargins*2 + meta_proc->w;
20010 meta_proc->x = hmargins;
20011 window->h = meta_proc->y + meta_proc->h + ok_button->h + bmargin*2;
20012 ok_button->x = (window->w/2)-(ok_button->w/2);
20013 ok_button->y = meta_proc->y + meta_proc->h + bmargin;
20014 jwin_center_dialog(scriptinfo_dlg);
20015 }
20016
20017 void showScriptInfo(zasm_meta const* meta)
20018 {
20019 scriptinfo_dlg[3].dp = (void*)meta;
20020 scriptinfo_dlg[0].dp2 = get_zc_font(font_lfont);
20021 large_dialog(scriptinfo_dlg);
20022 jwin_zmeta_proc(MSG_START,&scriptinfo_dlg[3],0); //Calculate size before calling dialog
20023 jwin_center_dialog(scriptinfo_dlg);
20024 do_zqdialog(scriptinfo_dlg,2);
20025 }
20026
20027 void write_includepaths();
20028 void call_compile_settings();
20029 int32_t onZScriptCompilerSettings()
20030 {
20031 call_compile_settings();
20032 return D_O_K;
20033 }
20034
20035 void doEditZScript()
20036 {
20037 if(do_box_edit(zScript, "ZScript Buffer", false, false))
20038 saved=false;
20039 }
20040
20041 std::string qst_cfg_header_from_path(std::string path);
20042 extern char *filepath;
20043 string get_box_cfg_hdr(int num)
20044 {
20045 if(num)
20046 return "misc";
20047 return qst_cfg_header_from_path(filepath);
20048 }
20049
20050 //{ Start type-specific import dlgs
20051 12 static ListData ffscript_sel_dlg_list(ffscriptlist2, &font);
20052 12 static ListData itemscript_sel_dlg_list(itemscriptlist2, &font);
20053 12 static ListData comboscript_sel_dlg_list(comboscriptlist2, &font);
20054 12 static ListData gscript_sel_dlg_list(gscriptlist2, &font);
20055 static char npcscript_str_buf2[32];
20056 const char *npcscriptlist2(int32_t index, int32_t *list_size)
20057 {
20058 if(index>=0)
20059 {
20060 char buf[20];
20061 bound(index,0,254);
20062
20063 if(npcmap[index].scriptname=="")
20064 strcpy(buf, "<none>");
20065 else
20066 {
20067 strncpy(buf, npcmap[index].scriptname.c_str(), 19);
20068 buf[19]='\0';
20069 }
20070
20071 sprintf(npcscript_str_buf2,"%d: %s",index+1, buf);
20072 return npcscript_str_buf2;
20073 }
20074
20075 *list_size=(NUMSCRIPTGUYS-1);
20076 return NULL;
20077 }
20078 12 static ListData npcscript_sel_dlg_list(npcscriptlist2, &font);
20079 static char lweaponscript_str_buf2[32];
20080 const char *lweaponscriptlist2(int32_t index, int32_t *list_size)
20081 {
20082 if(index>=0)
20083 {
20084 char buf[20];
20085 bound(index,0,254);
20086
20087 if(lwpnmap[index].scriptname=="")
20088 strcpy(buf, "<none>");
20089 else
20090 {
20091 strncpy(buf, lwpnmap[index].scriptname.c_str(), 19);
20092 buf[19]='\0';
20093 }
20094
20095 sprintf(lweaponscript_str_buf2,"%d: %s",index+1, buf);
20096 return lweaponscript_str_buf2;
20097 }
20098
20099 *list_size=(NUMSCRIPTWEAPONS-1);
20100 return NULL;
20101 }
20102 12 static ListData lweaponscript_sel_dlg_list(lweaponscriptlist2, &font);
20103 static char eweaponscript_str_buf2[32];
20104 const char *eweaponscriptlist2(int32_t index, int32_t *list_size)
20105 {
20106 if(index>=0)
20107 {
20108 char buf[20];
20109 bound(index,0,254);
20110
20111 if(ewpnmap[index].scriptname=="")
20112 strcpy(buf, "<none>");
20113 else
20114 {
20115 strncpy(buf, ewpnmap[index].scriptname.c_str(), 19);
20116 buf[19]='\0';
20117 }
20118
20119 sprintf(eweaponscript_str_buf2,"%d: %s",index+1, buf);
20120 return eweaponscript_str_buf2;
20121 }
20122
20123 *list_size=(NUMSCRIPTWEAPONS-1);
20124 return NULL;
20125 }
20126 12 static ListData eweaponscript_sel_dlg_list(eweaponscriptlist2, &font);
20127 static char playerscript_str_buf2[32];
20128 const char *playerscriptlist2(int32_t index, int32_t *list_size)
20129 {
20130 if(index>=0)
20131 {
20132 char buf[20];
20133 bound(index,0,3);
20134
20135 if(playermap[index].scriptname=="")
20136 strcpy(buf, "<none>");
20137 else
20138 {
20139 strncpy(buf, playermap[index].scriptname.c_str(), 19);
20140 buf[19]='\0';
20141 }
20142
20143 if(index==0)
20144 sprintf(playerscript_str_buf2,"Init: %s", buf);
20145
20146 if(index==1)
20147 sprintf(playerscript_str_buf2,"Active: %s", buf);
20148
20149 if(index==2)
20150 sprintf(playerscript_str_buf2,"Death: %s", buf);
20151
20152
20153 //sprintf(playerscript_str_buf2,"%d: %s",index+1, buf);
20154 return playerscript_str_buf2;
20155 }
20156
20157 *list_size=(NUMSCRIPTHERO-1);
20158 return NULL;
20159 }
20160 static char itemspritescript_str_buf2[32];
20161 const char *itemspritescriptlist2(int32_t index, int32_t *list_size)
20162 {
20163 if(index>=0)
20164 {
20165 char buf[20];
20166 bound(index,0,254);
20167
20168 if(itemspritemap[index].scriptname=="")
20169 strcpy(buf, "<none>");
20170 else
20171 {
20172 strncpy(buf, itemspritemap[index].scriptname.c_str(), 19);
20173 buf[19]='\0';
20174 }
20175
20176 sprintf(itemspritescript_str_buf2,"%d: %s",index+1, buf);
20177 return itemspritescript_str_buf2;
20178 }
20179
20180 *list_size=(NUMSCRIPTSITEMSPRITE-1);
20181 return NULL;
20182 }
20183 12 static ListData playerscript_sel_dlg_list(playerscriptlist2, &font);
20184 static char dmapscript_str_buf2[32];
20185 const char *dmapscriptlist2(int32_t index, int32_t *list_size)
20186 {
20187 if(index>=0)
20188 {
20189 char buf[20];
20190 bound(index,0,254);
20191
20192 if(dmapmap[index].scriptname=="")
20193 strcpy(buf, "<none>");
20194 else
20195 {
20196 strncpy(buf, dmapmap[index].scriptname.c_str(), 19);
20197 buf[19]='\0';
20198 }
20199
20200 sprintf(dmapscript_str_buf2,"%d: %s",index+1, buf);
20201 return dmapscript_str_buf2;
20202 }
20203
20204 *list_size=(NUMSCRIPTSDMAP-1);
20205 return NULL;
20206 }
20207 12 static ListData dmapscript_sel_dlg_list(dmapscriptlist2, &font);
20208 12 static ListData itemspritescript_sel_dlg_list(itemspritescriptlist2, &font);
20209 static char screenscript_str_buf2[32];
20210 const char *screenscriptlist2(int32_t index, int32_t *list_size)
20211 {
20212 if(index>=0)
20213 {
20214 char buf[20];
20215 bound(index,0,254);
20216
20217 if(screenmap[index].scriptname=="")
20218 strcpy(buf, "<none>");
20219 else
20220 {
20221 strncpy(buf, screenmap[index].scriptname.c_str(), 19);
20222 buf[19]='\0';
20223 }
20224
20225 sprintf(screenscript_str_buf2,"%d: %s",index+1, buf);
20226 return screenscript_str_buf2;
20227 }
20228
20229 *list_size=(NUMSCRIPTSCREEN-1);
20230 return NULL;
20231 }
20232 12 static ListData screenscript_sel_dlg_list(screenscriptlist2, &font);
20233 //} End type-specific import dlgs
20234
20235 6 void clear_map_states()
20236 {
20237
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(map<int32_t, script_slot_data>::iterator it = ffcmap.begin();
20238 3072 it != ffcmap.end(); ++it)
20239 {
20240 3066 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20241 3066 }
20242
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(map<int32_t, script_slot_data>::iterator it = globalmap.begin();
20243 54 it != globalmap.end(); ++it)
20244 {
20245 48 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20246 48 }
20247
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(map<int32_t, script_slot_data>::iterator it = itemmap.begin();
20248 1536 it != itemmap.end(); ++it)
20249 {
20250 1530 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20251 1530 }
20252
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(map<int32_t, script_slot_data>::iterator it = npcmap.begin();
20253 1536 it != npcmap.end(); ++it)
20254 {
20255 1530 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20256 1530 }
20257
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(map<int32_t, script_slot_data>::iterator it = ewpnmap.begin();
20258 1536 it != ewpnmap.end(); ++it)
20259 {
20260 1530 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20261 1530 }
20262
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(map<int32_t, script_slot_data>::iterator it = lwpnmap.begin();
20263 1536 it != lwpnmap.end(); ++it)
20264 {
20265 1530 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20266 1530 }
20267
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 6 times.
30 for(map<int32_t, script_slot_data>::iterator it = playermap.begin();
20268 30 it != playermap.end(); ++it)
20269 {
20270 24 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20271 24 }
20272
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(map<int32_t, script_slot_data>::iterator it = dmapmap.begin();
20273 1536 it != dmapmap.end(); ++it)
20274 {
20275 1530 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20276 1530 }
20277
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(map<int32_t, script_slot_data>::iterator it = screenmap.begin();
20278 1536 it != screenmap.end(); ++it)
20279 {
20280 1530 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20281 1530 }
20282
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(map<int32_t, script_slot_data>::iterator it = itemspritemap.begin();
20283 1536 it != itemspritemap.end(); ++it)
20284 {
20285 1530 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20286 1530 }
20287
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(map<int32_t, script_slot_data>::iterator it = comboscriptmap.begin();
20288 3072 it != comboscriptmap.end(); ++it)
20289 {
20290 3066 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20291 3066 }
20292 6 }
20293
20294 void clearAssignSlotDlg()
20295 {
20296 assignscript_dlg[0].dp2 = get_zc_font(font_lfont);
20297 assignscript_dlg[4].d1 = -1;
20298 assignscript_dlg[5].d1 = -1;
20299 assignscript_dlg[7].d1 = -1;
20300 assignscript_dlg[8].d1 = -1;
20301 assignscript_dlg[10].d1 = -1;
20302 assignscript_dlg[11].d1 = -1;
20303 assignscript_dlg[13].flags = 0;
20304 }
20305
20306 void inc_script_name(string& name)
20307 {
20308 size_t pos = name.find_last_not_of("0123456789");
20309 pos = name.find_first_of("0123456789",pos);
20310 std::ostringstream oss;
20311 if(pos == string::npos)
20312 {
20313 oss << name << 2;
20314 }
20315 else
20316 {
20317 int32_t val = atoi(name.substr(pos).c_str());
20318 oss << name.substr(0,pos) << val+1;
20319 }
20320 name = oss.str();
20321 }
20322
20323 enum script_slot_type
20324 {
20325 type_ffc, type_global, type_itemdata, type_npc, type_lweapon, type_eweapon,
20326 type_hero, type_dmap, type_screen, type_itemsprite, type_combo, type_generic,
20327 type_subscreen, num_types
20328 };
20329 script_slot_type getType(ScriptType type)
20330 {
20331 switch(type)
20332 {
20333 case ScriptType::FFC: return type_ffc;
20334 case ScriptType::Global: return type_global;
20335 case ScriptType::Item: return type_itemdata;
20336 case ScriptType::NPC: return type_npc;
20337 case ScriptType::Lwpn: return type_lweapon;
20338 case ScriptType::Ewpn: return type_eweapon;
20339 case ScriptType::Hero: return type_hero;
20340 case ScriptType::DMap:
20341 case ScriptType::ScriptedActiveSubscreen:
20342 case ScriptType::ScriptedPassiveSubscreen:
20343 case ScriptType::OnMap:
20344 return type_dmap;
20345 case ScriptType::Generic: case ScriptType::GenericFrozen:
20346 return type_generic;
20347 case ScriptType::Screen: return type_screen;
20348 case ScriptType::ItemSprite: return type_itemsprite;
20349 case ScriptType::Combo: return type_combo;
20350 case ScriptType::EngineSubscreen: return type_subscreen;
20351 default: return type_ffc; //Default
20352 }
20353 }
20354 #define SLOTMSGFLAG_MISSING 0x01
20355 #define SLOTMSG_SIZE 512
20356 bool checkSkip(int32_t format, byte flags)
20357 {
20358 switch(format)
20359 {
20360 case SCRIPT_FORMAT_DEFAULT:
20361 return (flags != 0);
20362 case SCRIPT_FORMAT_INVALID:
20363 return ((flags & SLOTMSGFLAG_MISSING)==0);
20364 default: return true;
20365 }
20366 }
20367 void clearAllSlots(int32_t type, byte flags = 0)
20368 {
20369 bound(type,0,num_types-1);
20370 switch(type)
20371 {
20372 case type_ffc:
20373 {
20374 for(int32_t q = 0; q < NUMSCRIPTFFC-1; ++q)
20375 {
20376 if(checkSkip(ffcmap[q].format, flags)) continue;
20377 ffcmap[q].scriptname = "";
20378 ffcmap[q].format = SCRIPT_FORMAT_DEFAULT;
20379 }
20380 break;
20381 }
20382 case type_global:
20383 {
20384 //Start at 1 to not clear Init
20385 for(int32_t q = 1; q < NUMSCRIPTGLOBAL; ++q)
20386 {
20387 if(checkSkip(globalmap[q].format, flags)) continue;
20388 globalmap[q].scriptname = "";
20389 globalmap[q].format = SCRIPT_FORMAT_DEFAULT;
20390 }
20391 break;
20392 }
20393 case type_itemdata:
20394 {
20395 for(int32_t q = 0; q < NUMSCRIPTITEM-1; ++q)
20396 {
20397 if(checkSkip(itemmap[q].format, flags)) continue;
20398 itemmap[q].scriptname = "";
20399 itemmap[q].format = SCRIPT_FORMAT_DEFAULT;
20400 }
20401 break;
20402 }
20403 case type_npc:
20404 {
20405 for(int32_t q = 0; q < NUMSCRIPTGUYS-1; ++q)
20406 {
20407 if(checkSkip(npcmap[q].format, flags)) continue;
20408 npcmap[q].scriptname = "";
20409 npcmap[q].format = SCRIPT_FORMAT_DEFAULT;
20410 }
20411 break;
20412 }
20413 case type_lweapon:
20414 {
20415 for(int32_t q = 0; q < NUMSCRIPTWEAPONS-1; ++q)
20416 {
20417 if(checkSkip(lwpnmap[q].format, flags)) continue;
20418 lwpnmap[q].scriptname = "";
20419 lwpnmap[q].format = SCRIPT_FORMAT_DEFAULT;
20420 }
20421 break;
20422 }
20423 case type_eweapon:
20424 {
20425 for(int32_t q = 0; q < NUMSCRIPTWEAPONS-1; ++q)
20426 {
20427 if(checkSkip(ewpnmap[q].format, flags)) continue;
20428 ewpnmap[q].scriptname = "";
20429 ewpnmap[q].format = SCRIPT_FORMAT_DEFAULT;
20430 }
20431 break;
20432 }
20433 case type_hero:
20434 {
20435 for(int32_t q = 0; q < NUMSCRIPTHERO-1; ++q)
20436 {
20437 if(checkSkip(playermap[q].format, flags)) continue;
20438 playermap[q].scriptname = "";
20439 playermap[q].format = SCRIPT_FORMAT_DEFAULT;
20440 }
20441 break;
20442 }
20443 case type_dmap:
20444 {
20445 for(int32_t q = 0; q < NUMSCRIPTSDMAP-1; ++q)
20446 {
20447 if(checkSkip(dmapmap[q].format, flags)) continue;
20448 dmapmap[q].scriptname = "";
20449 dmapmap[q].format = SCRIPT_FORMAT_DEFAULT;
20450 }
20451 break;
20452 }
20453 case type_screen:
20454 {
20455 for(int32_t q = 0; q < NUMSCRIPTSCREEN-1; ++q)
20456 {
20457 if(checkSkip(screenmap[q].format, flags)) continue;
20458 screenmap[q].scriptname = "";
20459 screenmap[q].format = SCRIPT_FORMAT_DEFAULT;
20460 }
20461 break;
20462 }
20463 case type_itemsprite:
20464 {
20465 for(int32_t q = 0; q < NUMSCRIPTSITEMSPRITE-1; ++q)
20466 {
20467 if(checkSkip(itemspritemap[q].format, flags)) continue;
20468 itemspritemap[q].scriptname = "";
20469 itemspritemap[q].format = SCRIPT_FORMAT_DEFAULT;
20470 }
20471 break;
20472 }
20473 case type_combo:
20474 {
20475 for(int32_t q = 0; q < NUMSCRIPTSCOMBODATA-1; ++q)
20476 {
20477 if(checkSkip(comboscriptmap[q].format, flags)) continue;
20478 comboscriptmap[q].scriptname = "";
20479 comboscriptmap[q].format = SCRIPT_FORMAT_DEFAULT;
20480 }
20481 break;
20482 }
20483 case type_generic:
20484 {
20485 for(int32_t q = 0; q < NUMSCRIPTSGENERIC-1; ++q)
20486 {
20487 if(checkSkip(genericmap[q].format, flags)) continue;
20488 genericmap[q].scriptname = "";
20489 genericmap[q].format = SCRIPT_FORMAT_DEFAULT;
20490 }
20491 break;
20492 }
20493 case type_subscreen:
20494 {
20495 for(int32_t q = 0; q < NUMSCRIPTSSUBSCREEN-1; ++q)
20496 {
20497 if(checkSkip(subscreenmap[q].format, flags)) continue;
20498 subscreenmap[q].scriptname = "";
20499 subscreenmap[q].format = SCRIPT_FORMAT_DEFAULT;
20500 }
20501 break;
20502 }
20503 }
20504 }
20505
20506 static bool doslots_log_output = false, doslots_comment_output = true;
20507 6 void setup_scriptslot_dlg(char* buf, byte flags)
20508 {
20509 //{ Set up the textbox at the bottom, and auto-resize height based on it
20510 6 int32_t prev_height = assignscript_dlg[14].h;
20511 6 memset(buf, 0, SLOTMSG_SIZE);
20512 //
20513 6 strcpy(buf, "Slots with matching names have been updated.\n");
20514
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 if(flags & SLOTMSGFLAG_MISSING)
20515 3 strcat(buf,"Scripts prefixed with '--' were not found, and will not function.\n");
20516 6 strcat(buf,"Global scripts named 'Init' will be appended to '~Init'");
20517 //
20518
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 SETFLAG(assignscript_dlg[13].flags, D_SELECTED, doslots_log_output);
20519
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 SETFLAG(assignscript_dlg[51].flags, D_SELECTED, doslots_comment_output);
20520 6 assignscript_dlg[14].dp = buf;
20521 6 object_message(&assignscript_dlg[14], MSG_START, 0); //Set the width/height
20522
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(int32_t diff = assignscript_dlg[14].h - prev_height) //resize dlg
20523 {
20524 6 int32_t prev_bottom = assignscript_dlg[14].y + prev_height;
20525
2/2
✓ Branch 0 taken 306 times.
✓ Branch 1 taken 6 times.
312 for(int32_t q = 1; assignscript_dlg[q].proc; ++q)
20526 {
20527
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 300 times.
306 if(q==14) continue; //Don't change self
20528
2/2
✓ Branch 0 taken 276 times.
✓ Branch 1 taken 24 times.
300 if(assignscript_dlg[q].y < prev_bottom) continue; //above proc
20529 24 assignscript_dlg[q].y += diff;
20530 24 }
20531 6 assignscript_dlg[0].h += diff;
20532 6 jwin_center_dialog(assignscript_dlg);
20533 6 }
20534 //}
20535 6 }
20536
20537 std::string global_slotnames[NUMSCRIPTGLOBAL] = {
20538 "Init",
20539 "Active",
20540 "onExit",
20541 "onSaveLoad",
20542 "onLaunch",
20543 "onContGame",
20544 "onF6Menu",
20545 "onSave",
20546 };
20547 std::string player_slotnames[NUMSCRIPTHERO-1] = {
20548 "Init",
20549 "Active",
20550 "onDeath",
20551 "onWin",
20552 };
20553 6 byte reload_scripts(map<string, disassembled_script_data> &scripts)
20554 {
20555 6 byte slotflags = 0;
20556 char temp[100];
20557
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(int32_t i = 0; i < NUMSCRIPTFFC-1; i++)
20558 {
20559
2/2
✓ Branch 0 taken 2987 times.
✓ Branch 1 taken 79 times.
3066 if(ffcmap[i].isEmpty())
20560 2987 sprintf(temp, "Slot %d:", i+1);
20561 else
20562 {
20563 79 sprintf(temp, "Slot %d:", i+1);
20564
2/2
✓ Branch 0 taken 73 times.
✓ Branch 1 taken 6 times.
79 if(scripts.find(ffcmap[i].scriptname) != scripts.end())
20565 73 ffcmap[i].format = SCRIPT_FORMAT_DEFAULT;
20566 else // Previously loaded script not found
20567 {
20568 6 ffcmap[i].format = SCRIPT_FORMAT_INVALID;
20569 6 slotflags |= SLOTMSGFLAG_MISSING;
20570 }
20571 }
20572 3066 ffcmap[i].slotname = temp;
20573 3066 ffcmap[i].update();
20574 3066 }
20575
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(int32_t i = 0; i < NUMSCRIPTGLOBAL; i++)
20576 {
20577
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 globalmap[i].slotname=fmt::format("{}:",global_slotnames[i]);
20578
2/2
✓ Branch 0 taken 37 times.
✓ Branch 1 taken 11 times.
48 if(!globalmap[i].isEmpty())
20579 {
20580
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 if(scripts.find(globalmap[i].scriptname) != scripts.end() || globalmap[i].scriptname == "~Init")
20581 11 globalmap[i].format = SCRIPT_FORMAT_DEFAULT;
20582 else // Unloaded
20583 {
20584 globalmap[i].format = SCRIPT_FORMAT_INVALID;
20585 slotflags |= SLOTMSGFLAG_MISSING;
20586 }
20587 11 }
20588 48 globalmap[i].update();
20589 48 }
20590
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(int32_t i = 0; i < NUMSCRIPTITEM-1; i++)
20591 {
20592
2/2
✓ Branch 0 taken 1517 times.
✓ Branch 1 taken 13 times.
1530 if(itemmap[i].isEmpty())
20593 1517 sprintf(temp, "Slot %d:", i+1);
20594 else
20595 {
20596 13 sprintf(temp, "Slot %d:", i+1);
20597
1/2
✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
13 if(scripts.find(itemmap[i].scriptname) != scripts.end())
20598 13 itemmap[i].format = SCRIPT_FORMAT_DEFAULT;
20599 else // Previously loaded script not found
20600 {
20601 itemmap[i].format = SCRIPT_FORMAT_INVALID;
20602 slotflags |= SLOTMSGFLAG_MISSING;
20603 }
20604 }
20605 1530 itemmap[i].slotname = temp;
20606 1530 itemmap[i].update();
20607 1530 }
20608
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(int32_t i = 0; i < NUMSCRIPTGUYS-1; i++)
20609 {
20610
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(npcmap[i].isEmpty())
20611 1530 sprintf(temp, "Slot %d:", i+1);
20612 else
20613 {
20614 sprintf(temp, "Slot %d:", i+1);
20615 if(scripts.find(npcmap[i].scriptname) != scripts.end())
20616 npcmap[i].format = SCRIPT_FORMAT_DEFAULT;
20617 else // Previously loaded script not found
20618 {
20619 npcmap[i].format = SCRIPT_FORMAT_INVALID;
20620 slotflags |= SLOTMSGFLAG_MISSING;
20621 }
20622 }
20623 1530 npcmap[i].slotname = temp;
20624 1530 npcmap[i].update();
20625 1530 }
20626
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(int32_t i = 0; i < NUMSCRIPTWEAPONS-1; i++)
20627 {
20628
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(ewpnmap[i].isEmpty())
20629 1530 sprintf(temp, "Slot %d:", i+1);
20630 else
20631 {
20632 sprintf(temp, "Slot %d:", i+1);
20633 if(scripts.find(ewpnmap[i].scriptname) != scripts.end())
20634 ewpnmap[i].format = SCRIPT_FORMAT_DEFAULT;
20635 else // Previously loaded script not found
20636 {
20637 ewpnmap[i].format = SCRIPT_FORMAT_INVALID;
20638 slotflags |= SLOTMSGFLAG_MISSING;
20639 }
20640 }
20641 1530 ewpnmap[i].slotname = temp;
20642 1530 ewpnmap[i].update();
20643 1530 }
20644
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(int32_t i = 0; i < NUMSCRIPTWEAPONS-1; i++)
20645 {
20646
2/2
✓ Branch 0 taken 1529 times.
✓ Branch 1 taken 1 times.
1530 if(lwpnmap[i].isEmpty())
20647 1529 sprintf(temp, "Slot %d:", i+1);
20648 else
20649 {
20650 1 sprintf(temp, "Slot %d:", i+1);
20651
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(scripts.find(lwpnmap[i].scriptname) != scripts.end())
20652 1 lwpnmap[i].format = SCRIPT_FORMAT_DEFAULT;
20653 else // Previously loaded script not found
20654 {
20655 lwpnmap[i].format = SCRIPT_FORMAT_INVALID;
20656 slotflags |= SLOTMSGFLAG_MISSING;
20657 }
20658 }
20659 1530 lwpnmap[i].slotname = temp;
20660 1530 lwpnmap[i].update();
20661 1530 }
20662
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 6 times.
30 for(int32_t i = 0; i < NUMSCRIPTHERO-1; i++)
20663 {
20664
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 playermap[i].slotname=fmt::format("{}:",player_slotnames[i]);
20665
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!playermap[i].isEmpty())
20666 {
20667 if(scripts.find(playermap[i].scriptname) != scripts.end())
20668 playermap[i].format = SCRIPT_FORMAT_DEFAULT;
20669 else // Unloaded
20670 {
20671 playermap[i].format = SCRIPT_FORMAT_INVALID;
20672 slotflags |= SLOTMSGFLAG_MISSING;
20673 }
20674 }
20675 24 playermap[i].update();
20676 24 }
20677
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(int32_t i = 0; i < NUMSCRIPTSCREEN-1; i++)
20678 {
20679
2/2
✓ Branch 0 taken 1528 times.
✓ Branch 1 taken 2 times.
1530 if(screenmap[i].isEmpty())
20680 1528 sprintf(temp, "Slot %d:", i+1);
20681 else
20682 {
20683 2 sprintf(temp, "Slot %d:", i+1);
20684
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(scripts.find(screenmap[i].scriptname) != scripts.end())
20685 2 screenmap[i].format = SCRIPT_FORMAT_DEFAULT;
20686 else // Previously loaded script not found
20687 {
20688 screenmap[i].format = SCRIPT_FORMAT_INVALID;
20689 slotflags |= SLOTMSGFLAG_MISSING;
20690 }
20691 }
20692 1530 screenmap[i].slotname = temp;
20693 1530 screenmap[i].update();
20694 1530 }
20695
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(int32_t i = 0; i < NUMSCRIPTSDMAP-1; i++)
20696 {
20697
2/2
✓ Branch 0 taken 1525 times.
✓ Branch 1 taken 5 times.
1530 if(dmapmap[i].isEmpty())
20698 1525 sprintf(temp, "Slot %d:", i+1);
20699 else
20700 {
20701 5 sprintf(temp, "Slot %d:", i+1);
20702
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if(scripts.find(dmapmap[i].scriptname) != scripts.end())
20703 5 dmapmap[i].format = SCRIPT_FORMAT_DEFAULT;
20704 else // Previously loaded script not found
20705 {
20706 dmapmap[i].format = SCRIPT_FORMAT_INVALID;
20707 slotflags |= SLOTMSGFLAG_MISSING;
20708 }
20709 }
20710 1530 dmapmap[i].slotname = temp;
20711 1530 dmapmap[i].update();
20712 1530 }
20713
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(int32_t i = 0; i < NUMSCRIPTSITEMSPRITE-1; i++)
20714 {
20715
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(itemspritemap[i].isEmpty())
20716 1530 sprintf(temp, "Slot %d:", i+1);
20717 else
20718 {
20719 sprintf(temp, "Slot %d:", i+1);
20720 if(scripts.find(itemspritemap[i].scriptname) != scripts.end())
20721 itemspritemap[i].format = SCRIPT_FORMAT_DEFAULT;
20722 else // Previously loaded script not found
20723 {
20724 itemspritemap[i].format = SCRIPT_FORMAT_INVALID;
20725 slotflags |= SLOTMSGFLAG_MISSING;
20726 }
20727 }
20728 1530 itemspritemap[i].slotname = temp;
20729 1530 itemspritemap[i].update();
20730 1530 }
20731
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(int32_t i = 0; i < NUMSCRIPTSCOMBODATA-1; i++)
20732 {
20733
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(comboscriptmap[i].isEmpty())
20734 3066 sprintf(temp, "Slot %d:", i+1);
20735 else
20736 {
20737 sprintf(temp, "Slot %d:", i+1);
20738 if(scripts.find(comboscriptmap[i].scriptname) != scripts.end())
20739 comboscriptmap[i].format = SCRIPT_FORMAT_DEFAULT;
20740 else // Previously loaded script not found
20741 {
20742 comboscriptmap[i].format = SCRIPT_FORMAT_INVALID;
20743 slotflags |= SLOTMSGFLAG_MISSING;
20744 }
20745 }
20746 3066 comboscriptmap[i].slotname = temp;
20747 3066 comboscriptmap[i].update();
20748 3066 }
20749
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(int32_t i = 0; i < NUMSCRIPTSGENERIC-1; i++)
20750 {
20751
2/2
✓ Branch 0 taken 3045 times.
✓ Branch 1 taken 21 times.
3066 if(genericmap[i].isEmpty())
20752 3045 sprintf(temp, "Slot %d:", i+1);
20753 else
20754 {
20755 21 sprintf(temp, "Slot %d:", i+1);
20756
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 1 times.
21 if(scripts.find(genericmap[i].scriptname) != scripts.end())
20757 20 genericmap[i].format = SCRIPT_FORMAT_DEFAULT;
20758 else // Previously loaded script not found
20759 {
20760 1 genericmap[i].format = SCRIPT_FORMAT_INVALID;
20761 1 slotflags |= SLOTMSGFLAG_MISSING;
20762 }
20763 }
20764 3066 genericmap[i].slotname = temp;
20765 3066 genericmap[i].update();
20766 3066 }
20767
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(int32_t i = 0; i < NUMSCRIPTSSUBSCREEN-1; i++)
20768 {
20769
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(subscreenmap[i].isEmpty())
20770 1530 sprintf(temp, "Slot %d:", i+1);
20771 else
20772 {
20773 sprintf(temp, "Slot %d:", i+1);
20774 if(scripts.find(subscreenmap[i].scriptname) != scripts.end())
20775 subscreenmap[i].format = SCRIPT_FORMAT_DEFAULT;
20776 else // Previously loaded script not found
20777 {
20778 subscreenmap[i].format = SCRIPT_FORMAT_INVALID;
20779 slotflags |= SLOTMSGFLAG_MISSING;
20780 }
20781 }
20782 1530 subscreenmap[i].slotname = temp;
20783 1530 subscreenmap[i].update();
20784 1530 }
20785 6 return slotflags;
20786 }
20787
20788 void doClearSlots(byte* flags);
20789
20790 extern byte compile_success_sample, compile_error_sample,
20791 compile_finish_sample, compile_audio_volume;
20792 static map<string, disassembled_script_data> *doslot_scripts = nullptr;
20793 21510 bool handle_slot(script_slot_data& slotdata, script_data* scriptdata)
20794 {
20795
2/2
✓ Branch 0 taken 125 times.
✓ Branch 1 taken 21385 times.
21510 if(slotdata.hasScriptData())
20796 {
20797 125 auto& data = (*doslot_scripts)[slotdata.scriptname];
20798 125 scriptdata->meta = data.meta;
20799 125 scriptdata->pc = data.pc;
20800 125 scriptdata->end_pc = data.end_pc;
20801 125 scriptdata->zasm_script = zasm_scripts[0];
20802 125 }
20803
1/2
✓ Branch 0 taken 21385 times.
✗ Branch 1 not taken.
21385 else if(scriptdata)
20804 {
20805 21385 scriptdata->zasm_script = nullptr;
20806 21385 scriptdata->meta.zero();
20807 21385 scriptdata->pc = 0;
20808 21385 scriptdata->end_pc = 0;
20809 21385 }
20810 21510 return true;
20811 }
20812 78 bool handle_slot_map(map<int32_t, script_slot_data>& mp, int offs, script_data** scriptdata)
20813 {
20814
2/2
✓ Branch 0 taken 21510 times.
✓ Branch 1 taken 78 times.
21588 for(auto it = mp.begin(); it != mp.end(); it++)
20815 {
20816
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21510 times.
21510 if(!handle_slot(it->second, scriptdata[it->first + offs]))
20817 return false;
20818 21510 }
20819 78 return true;
20820 78 }
20821
20822 void smart_slot_named(map<string, disassembled_script_data> &scripts,
20823 vector<string> const& scriptnames, map<int32_t, script_slot_data>& mp,
20824 std::string* slotnames, int slotstart, int slotend)
20825 {
20826 for(int q = slotstart; q < slotend; ++q)
20827 {
20828 auto& lval = mp[q];
20829 if(!lval.isEmpty())
20830 continue; //occupied, leave alone
20831 bool done = false;
20832 if(!done) //Check case-sensitive
20833 for(size_t rind = 0; rind < scriptnames.size(); ++rind)
20834 {
20835 auto const& rval = scriptnames[rind];
20836 if(rval == "<none>") continue;
20837 if(rval == slotnames[q])
20838 { //Perfect match
20839 lval.updateName(rval);
20840 lval.format = scripts[lval.scriptname].format;
20841 done = true;
20842 break;
20843 }
20844 }
20845 if(!done) //Check case-insensitive
20846 for(size_t rind = 0; rind < scriptnames.size(); ++rind)
20847 {
20848 auto const& rval = scriptnames[rind];
20849 if(rval == "<none>") continue;
20850 string lc_rv = rval, lc_slot = slotnames[q];
20851 lowerstr(lc_rv);
20852 lowerstr(lc_slot);
20853 if(lc_rv == lc_slot)
20854 { //Insensitive match
20855 lval.updateName(rval);
20856 lval.format = scripts[lval.scriptname].format;
20857 break;
20858 }
20859 }
20860 }
20861 }
20862 void smart_slot_type(map<string, disassembled_script_data> &scripts,
20863 vector<string> const& scriptnames, map<int32_t, script_slot_data>& mp,
20864 int slotcount)
20865 {
20866 for(size_t rind = 0; rind < scriptnames.size(); ++rind)
20867 {
20868 auto const& rval = scriptnames[rind];
20869 if(rval == "<none>") continue;
20870 script_slot_data* first_open_slot = nullptr;
20871 bool done = false;
20872 for(int q = 0; q < slotcount; ++q)
20873 {
20874 auto& lval = mp[q];
20875 if(lval.isEmpty())
20876 {
20877 if(!first_open_slot)
20878 first_open_slot = &lval;
20879 }
20880 else if(lval.scriptname == rval)
20881 {
20882 done = true;
20883 break;
20884 }
20885 }
20886 if(!done)
20887 {
20888 if(!first_open_slot)
20889 break; //no slots left to assign to!
20890 first_open_slot->updateName(rval);
20891 first_open_slot->format = scripts[first_open_slot->scriptname].format;
20892 }
20893 }
20894 }
20895
20896 6 bool do_slots(vector<shared_ptr<ZScript::Opcode>> const& zasm,
20897 map<string, disassembled_script_data> &scripts, int assign_mode)
20898 {
20899 6 large_dialog(assignscript_dlg);
20900 6 int32_t ret = 3;
20901 6 char slots_msg[SLOTMSG_SIZE] = {0};
20902 6 byte slotflags = reload_scripts(scripts);
20903 6 setup_scriptslot_dlg(slots_msg, slotflags);
20904 6 bool retval = false;
20905
20906 6 popup_zqdialog_start();
20907
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 while(!assign_mode)
20908 {
20909 slotflags = reload_scripts(scripts);
20910 ret = do_zqdialog(assignscript_dlg, ret);
20911
20912 switch(ret)
20913 {
20914 case 0:
20915 case 2:
20916 //Cancel
20917 goto exit_do_slots;
20918
20919 case 3: goto auto_do_slots;
20920
20921 case 6:
20922 //<<, FFC
20923 {
20924 int32_t lind = assignscript_dlg[4].d1;
20925 int32_t rind = assignscript_dlg[5].d1;
20926
20927 if(lind < 0 || rind < 0)
20928 break;
20929
20930 if(asffcscripts[rind] == "<none>")
20931 {
20932 ffcmap[lind].scriptname = "";
20933 ffcmap[lind].format = SCRIPT_FORMAT_DEFAULT;
20934 }
20935 else
20936 {
20937 ffcmap[lind].updateName(asffcscripts[rind]);
20938 ffcmap[lind].format = scripts[ffcmap[lind].scriptname].format;
20939 }
20940
20941 break;
20942 }
20943 case 9:
20944 //<<, Global
20945 {
20946 int32_t lind = assignscript_dlg[7].d1;
20947 int32_t rind = assignscript_dlg[8].d1;
20948
20949 if(lind < 0 || rind < 0)
20950 break;
20951
20952 if(lind == 0)
20953 {
20954 jwin_alert("Error","ZScript reserves this slot.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
20955 break;
20956 }
20957
20958 if(asglobalscripts[rind] == "<none>")
20959 {
20960 globalmap[lind].scriptname = "";
20961 globalmap[lind].format = SCRIPT_FORMAT_DEFAULT;
20962 }
20963 else
20964 {
20965 globalmap[lind].updateName(asglobalscripts[rind]);
20966 globalmap[lind].format = scripts[globalmap[lind].scriptname].format;
20967 }
20968
20969 break;
20970 }
20971 case 12:
20972 //<<, ITEM
20973 {
20974 int32_t lind = assignscript_dlg[10].d1;
20975 int32_t rind = assignscript_dlg[11].d1;
20976
20977 if(lind < 0 || rind < 0)
20978 break;
20979
20980 if(asitemscripts[rind] == "<none>")
20981 {
20982 itemmap[lind].scriptname = "";
20983 itemmap[lind].format = SCRIPT_FORMAT_DEFAULT;
20984 }
20985 else
20986 {
20987 itemmap[lind].updateName(asitemscripts[rind]);
20988 itemmap[lind].format = scripts[itemmap[lind].scriptname].format;
20989 }
20990
20991 break;
20992 }
20993 case 20:
20994 //<<, NPC
20995 {
20996 int32_t lind = assignscript_dlg[18].d1;
20997 int32_t rind = assignscript_dlg[19].d1;
20998
20999 if(lind < 0 || rind < 0)
21000 break;
21001
21002 if(asnpcscripts[rind] == "<none>")
21003 {
21004 npcmap[lind].scriptname = "";
21005 npcmap[lind].format = SCRIPT_FORMAT_DEFAULT;
21006 }
21007 else
21008 {
21009 npcmap[lind].updateName(asnpcscripts[rind]);
21010 npcmap[lind].format = scripts[npcmap[lind].scriptname].format;
21011 }
21012
21013 break;
21014 }
21015 case 23:
21016 //<<, LWeapon
21017 {
21018 int32_t lind = assignscript_dlg[21].d1;
21019 int32_t rind = assignscript_dlg[22].d1;
21020
21021 if(lind < 0 || rind < 0)
21022 break;
21023
21024 if(aslweaponscripts[rind] == "<none>")
21025 {
21026 lwpnmap[lind].scriptname = "";
21027 lwpnmap[lind].format = SCRIPT_FORMAT_DEFAULT;
21028 }
21029 else
21030 {
21031 lwpnmap[lind].updateName(aslweaponscripts[rind]);
21032 lwpnmap[lind].format = scripts[lwpnmap[lind].scriptname].format;
21033 }
21034
21035 break;
21036 }
21037 case 26:
21038 //<<, EWeapon
21039 {
21040 int32_t lind = assignscript_dlg[24].d1;
21041 int32_t rind = assignscript_dlg[25].d1;
21042
21043 if(lind < 0 || rind < 0)
21044 break;
21045
21046 if(aseweaponscripts[rind] == "<none>")
21047 {
21048 ewpnmap[lind].scriptname = "";
21049 ewpnmap[lind].format = SCRIPT_FORMAT_DEFAULT;
21050 }
21051 else
21052 {
21053 ewpnmap[lind].updateName(aseweaponscripts[rind]);
21054 ewpnmap[lind].format = scripts[ewpnmap[lind].scriptname].format;
21055 }
21056
21057 break;
21058 }
21059 case 29:
21060 //<<, Hero
21061 {
21062 int32_t lind = assignscript_dlg[27].d1;
21063 int32_t rind = assignscript_dlg[28].d1;
21064
21065 if(lind < 0 || rind < 0)
21066 break;
21067
21068 if(asplayerscripts[rind] == "<none>")
21069 {
21070 playermap[lind].scriptname = "";
21071 playermap[lind].format = SCRIPT_FORMAT_DEFAULT;
21072 }
21073 else
21074 {
21075 playermap[lind].updateName(asplayerscripts[rind]);
21076 playermap[lind].format = scripts[playermap[lind].scriptname].format;
21077 }
21078
21079 break;
21080 }
21081 case 32:
21082 //<<, Screendata
21083 {
21084 int32_t lind = assignscript_dlg[30].d1;
21085 int32_t rind = assignscript_dlg[31].d1;
21086
21087 if(lind < 0 || rind < 0)
21088 break;
21089
21090 if(asscreenscripts[rind] == "<none>")
21091 {
21092 screenmap[lind].scriptname = "";
21093 screenmap[lind].format = SCRIPT_FORMAT_DEFAULT;
21094 }
21095 else
21096 {
21097 screenmap[lind].updateName(asscreenscripts[rind]);
21098 screenmap[lind].format = scripts[screenmap[lind].scriptname].format;
21099 }
21100
21101 break;
21102 }
21103 case 35:
21104 //<<, dmapdata
21105 {
21106 int32_t lind = assignscript_dlg[33].d1;
21107 int32_t rind = assignscript_dlg[34].d1;
21108
21109 if(lind < 0 || rind < 0)
21110 break;
21111
21112 if(asdmapscripts[rind] == "<none>")
21113 {
21114 dmapmap[lind].scriptname = "";
21115 dmapmap[lind].format = SCRIPT_FORMAT_DEFAULT;
21116 }
21117 else
21118 {
21119 dmapmap[lind].updateName(asdmapscripts[rind]);
21120 dmapmap[lind].format = scripts[dmapmap[lind].scriptname].format;
21121 }
21122
21123 break;
21124 }
21125 case 38:
21126 //<<, itemsprite
21127 {
21128 int32_t lind = assignscript_dlg[36].d1;
21129 int32_t rind = assignscript_dlg[37].d1;
21130
21131 if(lind < 0 || rind < 0)
21132 break;
21133
21134 if(asitemspritescripts[rind] == "<none>")
21135 {
21136 itemspritemap[lind].scriptname = "";
21137 itemspritemap[lind].format = SCRIPT_FORMAT_DEFAULT;
21138 }
21139 else
21140 {
21141 itemspritemap[lind].updateName(asitemspritescripts[rind]);
21142 itemspritemap[lind].format = scripts[itemspritemap[lind].scriptname].format;
21143 }
21144
21145 break;
21146 }
21147 case 41:
21148 //<<, comboscript
21149 {
21150 int32_t lind = assignscript_dlg[39].d1;
21151 int32_t rind = assignscript_dlg[40].d1;
21152
21153 if(lind < 0 || rind < 0)
21154 break;
21155
21156 if(ascomboscripts[rind] == "<none>")
21157 {
21158 comboscriptmap[lind].scriptname = "";
21159 comboscriptmap[lind].format = SCRIPT_FORMAT_DEFAULT;
21160 }
21161 else
21162 {
21163 comboscriptmap[lind].updateName(ascomboscripts[rind]);
21164 comboscriptmap[lind].format = scripts[comboscriptmap[lind].scriptname].format;
21165 }
21166
21167 break;
21168 }
21169 case 47:
21170 //<<, generic script
21171 {
21172 int32_t lind = assignscript_dlg[45].d1;
21173 int32_t rind = assignscript_dlg[46].d1;
21174
21175 if(lind < 0 || rind < 0)
21176 break;
21177
21178 if(asgenericscripts[rind] == "<none>")
21179 {
21180 genericmap[lind].scriptname = "";
21181 genericmap[lind].format = SCRIPT_FORMAT_DEFAULT;
21182 }
21183 else
21184 {
21185 genericmap[lind].updateName(asgenericscripts[rind]);
21186 genericmap[lind].format = scripts[genericmap[lind].scriptname].format;
21187 }
21188
21189 break;
21190 }
21191 case 50:
21192 //<<, subscreen script
21193 {
21194 int32_t lind = assignscript_dlg[48].d1;
21195 int32_t rind = assignscript_dlg[49].d1;
21196
21197 if(lind < 0 || rind < 0)
21198 break;
21199
21200 if(assubscreenscripts[rind] == "<none>")
21201 {
21202 subscreenmap[lind].scriptname = "";
21203 subscreenmap[lind].format = SCRIPT_FORMAT_DEFAULT;
21204 }
21205 else
21206 {
21207 subscreenmap[lind].updateName(assubscreenscripts[rind]);
21208 subscreenmap[lind].format = scripts[subscreenmap[lind].scriptname].format;
21209 }
21210
21211 break;
21212 }
21213
21214 case 42:
21215 //Script Info, information
21216 {
21217 disassembled_script_data* target = nullptr;
21218 switch(get_selected_tab((TABPANEL*)assignscript_dlg[1].dp))
21219 {
21220 default:
21221 case 0: //FFC
21222 {
21223 int32_t id = assignscript_dlg[4].d1;
21224 if(id > -1 && ffcmap[id].hasScriptData())
21225 {
21226 target = &(scripts[ffcmap[id].scriptname]);
21227 }
21228 break;
21229 }
21230 case 1: //Global
21231 {
21232 int32_t id = assignscript_dlg[7].d1;
21233 if(id > -1 && globalmap[id].hasScriptData())
21234 {
21235 target = &(scripts[globalmap[id].scriptname]);
21236 }
21237 break;
21238 }
21239 case 2: //Item
21240 {
21241 int32_t id = assignscript_dlg[10].d1;
21242 if(id > -1 && itemmap[id].hasScriptData())
21243 {
21244 target = &(scripts[itemmap[id].scriptname]);
21245 }
21246 break;
21247 }
21248 case 3: //npc
21249 {
21250 int32_t id = assignscript_dlg[19].d1;
21251 if(id > -1 && npcmap[id].hasScriptData())
21252 {
21253 target = &(scripts[npcmap[id].scriptname]);
21254 }
21255 break;
21256 }
21257 case 4: //lweapon
21258 {
21259 int32_t id = assignscript_dlg[21].d1;
21260 if(id > -1 && lwpnmap[id].hasScriptData())
21261 {
21262 target = &(scripts[lwpnmap[id].scriptname]);
21263 }
21264 break;
21265 }
21266 case 5: //eweapon
21267 {
21268 int32_t id = assignscript_dlg[24].d1;
21269 if(id > -1 && ewpnmap[id].hasScriptData())
21270 {
21271 target = &(scripts[ewpnmap[id].scriptname]);
21272 }
21273 break;
21274 }
21275 case 6: //hero
21276 {
21277 int32_t id = assignscript_dlg[27].d1;
21278 if(id > -1 && playermap[id].hasScriptData())
21279 {
21280 target = &(scripts[playermap[id].scriptname]);
21281 }
21282 break;
21283 }
21284 case 7: //dmap
21285 {
21286 int32_t id = assignscript_dlg[33].d1;
21287 if(id > -1 && dmapmap[id].hasScriptData())
21288 {
21289 target = &(scripts[dmapmap[id].scriptname]);
21290 }
21291 break;
21292 }
21293 case 8: //screen
21294 {
21295 int32_t id = assignscript_dlg[30].d1;
21296 if(id > -1 && screenmap[id].hasScriptData())
21297 {
21298 target = &(scripts[screenmap[id].scriptname]);
21299 }
21300 break;
21301 }
21302 case 9: //itemsprite
21303 {
21304 int32_t id = assignscript_dlg[36].d1;
21305 if(id > -1 && itemspritemap[id].hasScriptData())
21306 {
21307 target = &(scripts[itemspritemap[id].scriptname]);
21308 }
21309 break;
21310 }
21311 case 10: //combo
21312 {
21313 int32_t id = assignscript_dlg[39].d1;
21314 if(id > -1 && comboscriptmap[id].hasScriptData())
21315 {
21316 target = &(scripts[comboscriptmap[id].scriptname]);
21317 }
21318 break;
21319 }
21320 case 11: //Generic
21321 {
21322 int32_t id = assignscript_dlg[45].d1;
21323 if(id > -1 && genericmap[id].hasScriptData())
21324 {
21325 target = &(scripts[genericmap[id].scriptname]);
21326 }
21327 break;
21328 }
21329 case 12: //Subscreen
21330 {
21331 int32_t id = assignscript_dlg[48].d1;
21332 if(id > -1 && subscreenmap[id].hasScriptData())
21333 {
21334 target = &(scripts[subscreenmap[id].scriptname]);
21335 }
21336 break;
21337 }
21338 }
21339 if(target)
21340 showScriptInfo(&target->meta);
21341 break;
21342 }
21343
21344 case 43:
21345 //Script Info, information
21346 {
21347 disassembled_script_data* target = NULL;
21348 switch(get_selected_tab((TABPANEL*)assignscript_dlg[1].dp))
21349 {
21350 default:
21351 case 0: //FFC
21352 {
21353 int32_t id = assignscript_dlg[5].d1;
21354 if(id < 0 || asffcscripts[id] == "<none>" || asffcscripts[id].at(0) == '-') break;
21355 target = &(scripts[asffcscripts[id]]);
21356 break;
21357 }
21358 case 1: //Global
21359 {
21360 int32_t id = assignscript_dlg[8].d1;
21361 if(id < 0 || asglobalscripts[id] == "<none>" || asglobalscripts[id].at(0) == '-') break;
21362 target = &(scripts[asglobalscripts[id]]);
21363 break;
21364 }
21365 case 2: //Item
21366 {
21367 int32_t id = assignscript_dlg[11].d1;
21368 if(id < 0 || asitemscripts[id] == "<none>" || asitemscripts[id].at(0) == '-') break;
21369 target = &(scripts[asitemscripts[id]]);
21370 break;
21371 }
21372 case 3: //npc
21373 {
21374 int32_t id = assignscript_dlg[20].d1;
21375 if(id < 0 || asnpcscripts[id] == "<none>" || asnpcscripts[id].at(0) == '-') break;
21376 target = &(scripts[asnpcscripts[id]]);
21377 break;
21378 }
21379 case 4: //lweapon
21380 {
21381 int32_t id = assignscript_dlg[22].d1;
21382 if(id < 0 || aslweaponscripts[id] == "<none>" || aslweaponscripts[id].at(0) == '-') break;
21383 target = &(scripts[aslweaponscripts[id]]);
21384 break;
21385 }
21386 case 5: //eweapon
21387 {
21388 int32_t id = assignscript_dlg[25].d1;
21389 if(id < 0 || aseweaponscripts[id] == "<none>" || aseweaponscripts[id].at(0) == '-') break;
21390 target = &(scripts[aseweaponscripts[id]]);
21391 break;
21392 }
21393 case 6: //hero
21394 {
21395 int32_t id = assignscript_dlg[28].d1;
21396 if(id < 0 || asplayerscripts[id] == "<none>" || asplayerscripts[id].at(0) == '-') break;
21397 target = &(scripts[asplayerscripts[id]]);
21398 break;
21399 }
21400 case 7: //dmap
21401 {
21402 int32_t id = assignscript_dlg[34].d1;
21403 if(id < 0 || asdmapscripts[id] == "<none>" || asdmapscripts[id].at(0) == '-') break;
21404 target = &(scripts[asdmapscripts[id]]);
21405 break;
21406 }
21407 case 8: //screen
21408 {
21409 int32_t id = assignscript_dlg[31].d1;
21410 if(id < 0 || asscreenscripts[id] == "<none>" || asscreenscripts[id].at(0) == '-') break;
21411 target = &(scripts[asscreenscripts[id]]);
21412 break;
21413 }
21414 case 9: //itemsprite
21415 {
21416 int32_t id = assignscript_dlg[37].d1;
21417 if(id < 0 || asitemspritescripts[id] == "<none>" || asitemspritescripts[id].at(0) == '-') break;
21418 target = &(scripts[asitemspritescripts[id]]);
21419 break;
21420 }
21421 case 10: //combo
21422 {
21423 int32_t id = assignscript_dlg[40].d1;
21424 if(id < 0 || ascomboscripts[id] == "<none>" || ascomboscripts[id].at(0) == '-') break;
21425 target = &(scripts[ascomboscripts[id]]);
21426 break;
21427 }
21428 case 11: //generic
21429 {
21430 int32_t id = assignscript_dlg[46].d1;
21431 if(id < 0 || asgenericscripts[id] == "<none>" || asgenericscripts[id].at(0) == '-') break;
21432 target = &(scripts[asgenericscripts[id]]);
21433 break;
21434 }
21435 case 12: //subscreen
21436 {
21437 int32_t id = assignscript_dlg[49].d1;
21438 if(id < 0 || assubscreenscripts[id] == "<none>" || assubscreenscripts[id].at(0) == '-') break;
21439 target = &(scripts[assubscreenscripts[id]]);
21440 break;
21441 }
21442 }
21443 if(target)
21444 showScriptInfo(&target->meta);
21445 break;
21446 }
21447
21448 case 44:
21449 //Clear, clear slots of current type- after a confirmation.
21450 {
21451 doClearSlots(&slotflags);
21452 break;
21453 }
21454 }
21455 }
21456
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(assign_mode == 2) //Smart Assign
21457 {
21458 //For global/hero scripts, match slot names if unoccupied
21459 smart_slot_named(scripts, asglobalscripts, globalmap, global_slotnames, 1, NUMSCRIPTGLOBAL);
21460 smart_slot_named(scripts, asplayerscripts, playermap, player_slotnames, 0, NUMSCRIPTHERO-1);
21461 //For other scripts, assign all un-assigned scripts
21462 smart_slot_type(scripts, asffcscripts, ffcmap, NUMSCRIPTFFC-1);
21463 smart_slot_type(scripts, asitemscripts, itemmap, NUMSCRIPTITEM-1);
21464 smart_slot_type(scripts, asnpcscripts, npcmap, NUMSCRIPTGUYS-1);
21465 smart_slot_type(scripts, aslweaponscripts, lwpnmap, NUMSCRIPTWEAPONS-1);
21466 smart_slot_type(scripts, aseweaponscripts, ewpnmap, NUMSCRIPTWEAPONS-1);
21467 smart_slot_type(scripts, asscreenscripts, screenmap, NUMSCRIPTSCREEN-1);
21468 smart_slot_type(scripts, asdmapscripts, dmapmap, NUMSCRIPTSDMAP-1);
21469 smart_slot_type(scripts, asitemspritescripts, itemspritemap, NUMSCRIPTSITEMSPRITE-1);
21470 smart_slot_type(scripts, ascomboscripts, comboscriptmap, NUMSCRIPTSCOMBODATA-1);
21471 smart_slot_type(scripts, asgenericscripts, genericmap, NUMSCRIPTSGENERIC-1);
21472 smart_slot_type(scripts, assubscreenscripts, subscreenmap, NUMSCRIPTSSUBSCREEN-1);
21473 }
21474 auto_do_slots:
21475 6 doslots_log_output = (assignscript_dlg[13].flags == D_SELECTED);
21476 6 doslots_comment_output = (assignscript_dlg[51].flags == D_SELECTED);
21477 6 doslot_scripts = &scripts;
21478 //OK
21479 {
21480
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(doslots_log_output)
21481 {
21482 string outstr;
21483 write_script(zasm, outstr, doslots_comment_output, doslot_scripts);
21484 safe_al_trace(outstr);
21485 }
21486 6 auto start_assign_time = std::chrono::steady_clock::now();
21487 6 string zasm_str;
21488
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 write_script(zasm, zasm_str, false, nullptr);
21489
21490 6 std::vector<ffscript> zasm;
21491
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(parse_script_string(zasm, zasm_str, false))
21492 goto exit_do_slots;
21493
21494 6 zasm_scripts.clear();
21495
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 zasm_scripts.emplace_back(std::make_shared<zasm_script>(std::move(zasm)));
21496
21497
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(ffcmap, 1, ffscripts))
21498 goto exit_do_slots;
21499
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(globalmap, 0, globalscripts))
21500 goto exit_do_slots;
21501
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(itemmap, 1, itemscripts))
21502 goto exit_do_slots;
21503
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(npcmap, 1, guyscripts))
21504 goto exit_do_slots;
21505
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(lwpnmap, 1, lwpnscripts))
21506 goto exit_do_slots;
21507
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(ewpnmap, 1, ewpnscripts))
21508 goto exit_do_slots;
21509
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(playermap, 1, playerscripts))
21510 goto exit_do_slots;
21511
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(dmapmap, 1, dmapscripts))
21512 goto exit_do_slots;
21513
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(screenmap, 1, screenscripts))
21514 goto exit_do_slots;
21515
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(itemspritemap, 1, itemspritescripts))
21516 goto exit_do_slots;
21517
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(comboscriptmap, 1, comboscripts))
21518 goto exit_do_slots;
21519
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(genericmap, 1, genericscripts))
21520 goto exit_do_slots;
21521
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(subscreenmap, 1, subscreenscripts))
21522 goto exit_do_slots;
21523
21524 6 auto end_assign_time = std::chrono::steady_clock::now();
21525
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
6 int compile_time_ms = std::chrono::duration_cast<std::chrono::milliseconds>(end_assign_time - start_assign_time).count();
21526
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 al_trace("Assign Slots took %d ms\n", compile_time_ms);
21527 6 char buf[256] = {0};
21528 12 sprintf(buf, "ZScripts successfully loaded into script slots"
21529 6 "\nAssign Slots took %d ms", compile_time_ms);
21530
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 compile_finish_sample = vbound(zc_get_config("Compiler","compile_finish_sample",20),0,255);
21531
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 compile_audio_volume = vbound(zc_get_config("Compiler","compile_audio_volume",200),0,255);
21532
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if ( compile_finish_sample > 0 )
21533 {
21534
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(sfxdat)
21535 sfx_voice[compile_finish_sample]=allocate_voice((SAMPLE*)sfxdata[compile_finish_sample].dat);
21536
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 else sfx_voice[compile_finish_sample]=allocate_voice(&customsfxdata[compile_finish_sample]);
21537
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 voice_set_volume(sfx_voice[compile_finish_sample], compile_audio_volume);
21538
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 voice_start(sfx_voice[compile_finish_sample]);
21539 6 }
21540
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!assign_mode)
21541 InfoDialog("Slots Assigned",buf).show();
21542
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if ( compile_finish_sample > 0 )
21543 {
21544
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(sfx_voice[compile_finish_sample]!=-1)
21545 {
21546
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 deallocate_voice(sfx_voice[compile_finish_sample]);
21547 6 sfx_voice[compile_finish_sample]=-1;
21548 6 }
21549 6 }
21550
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 build_biffs_list();
21551
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 build_biitems_list();
21552 6 retval = true;
21553 6 goto exit_do_slots;
21554
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 }
21555 exit_do_slots:
21556 6 doslot_scripts = nullptr;
21557 6 popup_zqdialog_end();
21558 6 return retval;
21559 }
21560
21561 static char slottype_str_buf[32];
21562
21563 const char *slottype_list(int32_t index, int32_t *list_size)
21564 {
21565 if(index >= 0)
21566 {
21567 bound(index,0,num_types-1);
21568
21569 switch(index)
21570 {
21571 case type_ffc:
21572 strcpy(slottype_str_buf, "FFC");
21573 break;
21574 case type_global:
21575 strcpy(slottype_str_buf, "Global");
21576 break;
21577 case type_itemdata:
21578 strcpy(slottype_str_buf, "Item");
21579 break;
21580 case type_npc:
21581 strcpy(slottype_str_buf, "NPC");
21582 break;
21583 case type_lweapon:
21584 strcpy(slottype_str_buf, "LWeapon");
21585 break;
21586 case type_eweapon:
21587 strcpy(slottype_str_buf, "EWeapon");
21588 break;
21589 case type_hero:
21590 strcpy(slottype_str_buf, "Hero");
21591 break;
21592 case type_dmap:
21593 strcpy(slottype_str_buf, "DMap");
21594 break;
21595 case type_screen:
21596 strcpy(slottype_str_buf, "Screen");
21597 break;
21598 case type_itemsprite:
21599 strcpy(slottype_str_buf, "ItemSprite");
21600 break;
21601 case type_combo:
21602 strcpy(slottype_str_buf, "Combo");
21603 break;
21604 case type_generic:
21605 strcpy(slottype_str_buf, "Generic");
21606 break;
21607 case type_subscreen:
21608 strcpy(slottype_str_buf, "Subscreen");
21609 break;
21610 }
21611
21612 return slottype_str_buf;
21613 }
21614 *list_size = 11;
21615 return NULL;
21616 }
21617 12 static ListData slottype_sel_list(slottype_list, &font);
21618
21619 static DIALOG clearslots_dlg[] =
21620 {
21621 12 { jwin_win_proc, 0, 0, 200, 159, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Clear Slots", NULL, NULL },
21622 12 { jwin_button_proc, 35, 132, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Confirm", NULL, NULL },
21623 12 { jwin_button_proc, 104, 132, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
21624 12 { jwin_droplist_proc, 50, 28+16, 70, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &slottype_sel_list, NULL, NULL },
21625 12 { jwin_radio_proc, 40, 34+00, 81, 9, vc(14), vc(1), 0, D_SELECTED, 0, 0, (void *) "Clear Script Type:", NULL, NULL },
21626 12 { jwin_radio_proc, 40, 34+32, 81, 9, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear Missing (--) Slots", NULL, NULL },
21627 12 { jwin_radio_proc, 40, 34+80, 81, 9, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear All", NULL, NULL },
21628 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
21629 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
21630 };
21631
21632 void doClearSlots(byte* flags)
21633 {
21634 //{ Setup
21635 clearslots_dlg[0].dp2=get_zc_font(font_lfont);
21636 clearslots_dlg[3].d1 = get_selected_tab((TABPANEL*)assignscript_dlg[1].dp); //Default to current tab's type
21637 clearslots_dlg[4].flags |= D_SELECTED;
21638 clearslots_dlg[5].flags &= ~D_SELECTED;
21639 clearslots_dlg[6].flags &= ~D_SELECTED;
21640 if(((*flags) & SLOTMSGFLAG_MISSING) == 0)
21641 clearslots_dlg[5].flags |= D_DISABLED;
21642 else
21643 clearslots_dlg[5].flags &= ~D_DISABLED;
21644 //}
21645
21646 large_dialog(clearslots_dlg);
21647
21648 if(do_zqdialog(clearslots_dlg,2)==1)
21649 {
21650 int32_t q = 3;
21651 while((clearslots_dlg[++q].flags & D_SELECTED) == 0);
21652 switch(q)
21653 {
21654 case 4: //Clear type
21655 {
21656 clearAllSlots(clearslots_dlg[3].d1);
21657 break;
21658 }
21659 case 5: //Clear Missing
21660 {
21661 for(int32_t q = 0; q <= 10; ++q)
21662 clearAllSlots(q,SLOTMSGFLAG_MISSING);
21663 break;
21664 }
21665 case 6: //Clear ALL
21666 {
21667 for(int32_t q = 0; q <= 10; ++q)
21668 clearAllSlots(q);
21669 break;
21670 }
21671 }
21672 }
21673 }
21674
21675 static DIALOG exportzasm_dlg[] =
21676 {
21677 12 { jwin_win_proc, 0, 0, 200, 159, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Export ZASM", NULL, NULL },
21678 12 { jwin_button_proc, 35, 132, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Confirm", NULL, NULL },
21679 12 { jwin_button_proc, 104, 132, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
21680 12 { jwin_droplist_proc, 50, 28+16, 100, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, D_EXIT, 0, 0, (void *) &slottype_sel_list, NULL, NULL },
21681 12 { jwin_droplist_proc, 50, 28+48, 100, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
21682 12 { jwin_text_proc, 50, 28+8, 16, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Script Type:", NULL, NULL },
21683 12 { jwin_text_proc, 50, 28+40, 16, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Script Slot:", NULL, NULL },
21684 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
21685 };
21686
21687 static DIALOG importzasm_dlg[] =
21688 {
21689 12 { jwin_win_proc, 0, 0, 200, 159, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Import ZASM", NULL, NULL },
21690 12 { jwin_button_proc, 35, 132, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Confirm", NULL, NULL },
21691 12 { jwin_button_proc, 104, 132, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
21692 12 { jwin_droplist_proc, 50, 28+16, 100, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, D_EXIT, 0, 0, (void *) &slottype_sel_list, NULL, NULL },
21693 12 { jwin_droplist_proc, 50, 28+48, 100, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
21694 // 5
21695 12 { jwin_text_proc, 50, 28+8, 16, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Script Type:", NULL, NULL },
21696 12 { jwin_text_proc, 50, 28+40, 16, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Script Slot:", NULL, NULL },
21697 12 { jwin_text_proc, 50, 28+72, 16, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Script Name:", NULL, NULL },
21698 12 { jwin_edit_proc, 50, 28+80, 100, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 19, 0, NULL, NULL, NULL },
21699
21700 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
21701 };
21702 extern ListData itemscript_list;
21703 extern ListData itemspritescript_list;
21704 extern ListData lweaponscript_list;
21705 extern ListData npcscript_list;
21706 extern ListData eweaponscript_list;
21707 extern ListData comboscript_list;
21708
21709 8 void center_zscript_dialogs()
21710 {
21711 8 jwin_center_dialog(exportzasm_dlg);
21712 8 jwin_center_dialog(importzasm_dlg);
21713 8 jwin_center_dialog(clearslots_dlg);
21714 8 }
21715
21716 // array of voices, one for each sfx sample in the data file
21717 // 0+ = voice #
21718 // -1 = voice not allocated
21719 int32_t sfx_voice[WAV_COUNT];
21720
21721 void Z_init_sound()
21722 {
21723 for(int32_t i=0; i<WAV_COUNT; i++)
21724 sfx_voice[i]=-1;
21725
21726 // master_volume(digi_volume,midi_volume);
21727 }
21728
21729 // returns number of voices currently allocated
21730 int32_t sfx_count()
21731 {
21732 int32_t c=0;
21733
21734 for(int32_t i=0; i<WAV_COUNT; i++)
21735 if(sfx_voice[i]!=-1)
21736 ++c;
21737
21738 return c;
21739 }
21740
21741 // clean up finished samples
21742 void sfx_cleanup()
21743 {
21744 for(int32_t i=0; i<WAV_COUNT; i++)
21745 if(sfx_voice[i]!=-1 && voice_get_position(sfx_voice[i])<0)
21746 {
21747 deallocate_voice(sfx_voice[i]);
21748 sfx_voice[i]=-1;
21749 }
21750 }
21751
21752 // allocates a voice for the sample "wav_index" (index into zelda.dat)
21753 // if a voice is already allocated (and/or playing), then it just returns true
21754 // Returns true: voice is allocated
21755 // false: unsuccessful
21756 SAMPLE templist[WAV_COUNT];
21757
21758 bool sfx_init(int32_t index)
21759 {
21760 // check index
21761 if(index<1 || index>=WAV_COUNT)
21762 return false;
21763
21764 if(sfx_voice[index]==-1)
21765 {
21766 sfx_voice[index]=allocate_voice(&templist[index]);
21767 }
21768
21769 return sfx_voice[index] != -1;
21770 }
21771
21772 // plays an sfx sample
21773 void sfx(int32_t index,int32_t pan,bool loop,bool restart,int32_t vol,int32_t freq)
21774 {
21775 if(!sfx_init(index))
21776 return;
21777
21778 voice_set_playmode(sfx_voice[index],loop?PLAYMODE_LOOP:PLAYMODE_PLAY);
21779 voice_set_pan(sfx_voice[index],pan);
21780
21781 int32_t pos = voice_get_position(sfx_voice[index]);
21782
21783 if(restart) voice_set_position(sfx_voice[index],0);
21784
21785 if(pos<=0)
21786 voice_start(sfx_voice[index]);
21787 }
21788
21789 // start it (in loop mode) if it's not already playing,
21790 // otherwise just leave it in its current position
21791 void cont_sfx(int32_t index)
21792 {
21793 if(!sfx_init(index))
21794 return;
21795
21796 if(voice_get_position(sfx_voice[index])<=0)
21797 {
21798 voice_set_position(sfx_voice[index],0);
21799 voice_set_playmode(sfx_voice[index],PLAYMODE_LOOP);
21800 voice_start(sfx_voice[index]);
21801 }
21802 }
21803
21804 // adjust parameters while playing
21805 void adjust_sfx(int32_t index,int32_t pan,bool loop)
21806 {
21807 if(index<0 || index>=WAV_COUNT || sfx_voice[index]==-1)
21808 return;
21809
21810 voice_set_playmode(sfx_voice[index],loop?PLAYMODE_LOOP:PLAYMODE_PLAY);
21811 voice_set_pan(sfx_voice[index],pan);
21812 }
21813
21814 // pauses a voice
21815 void pause_sfx(int32_t index)
21816 {
21817 if(index>=0 && index<WAV_COUNT && sfx_voice[index]!=-1)
21818 voice_stop(sfx_voice[index]);
21819 }
21820
21821 // resumes a voice
21822 void resume_sfx(int32_t index)
21823 {
21824 if(index>=0 && index<WAV_COUNT && sfx_voice[index]!=-1)
21825 voice_start(sfx_voice[index]);
21826 }
21827
21828 // pauses all active voices
21829 void pause_all_sfx()
21830 {
21831 for(int32_t i=0; i<WAV_COUNT; i++)
21832 if(sfx_voice[i]!=-1)
21833 voice_stop(sfx_voice[i]);
21834 }
21835
21836 // resumes all paused voices
21837 void resume_all_sfx()
21838 {
21839 for(int32_t i=0; i<WAV_COUNT; i++)
21840 if(sfx_voice[i]!=-1)
21841 voice_start(sfx_voice[i]);
21842 }
21843
21844 // stops an sfx and deallocates the voice
21845 void stop_sfx(int32_t index)
21846 {
21847 if(index<0 || index>=WAV_COUNT)
21848 return;
21849
21850 if(sfx_voice[index]!=-1)
21851 {
21852 deallocate_voice(sfx_voice[index]);
21853 sfx_voice[index]=-1;
21854 }
21855 }
21856
21857 void kill_sfx()
21858 {
21859 for(int32_t i=0; i<WAV_COUNT; i++)
21860 if(sfx_voice[i]!=-1)
21861 {
21862 deallocate_voice(sfx_voice[i]);
21863 sfx_voice[i]=-1;
21864 }
21865 }
21866
21867 int32_t pan(int32_t x)
21868 {
21869 return 128;
21870 /*switch(pan_style)
21871 {
21872 case 0: return 128;
21873 case 1: return vbound((x>>1)+68,0,255);
21874 case 2: return vbound(((x*3)>>2)+36,0,255);
21875 }
21876 return vbound(x,0,255);*/
21877 }
21878
21879
21880 void change_sfx(SAMPLE *sfx1, SAMPLE *sfx2)
21881 {
21882 sfx1->bits = sfx2->bits;
21883 sfx1->stereo = sfx2->stereo;
21884 sfx1->freq = sfx2->freq;
21885 sfx1->priority = sfx2->priority;
21886 sfx1->len = sfx2->len;
21887 sfx1->loop_start = sfx2->loop_start;
21888 sfx1->loop_end = sfx2->loop_end;
21889 sfx1->param = sfx2->param;
21890
21891 if(sfx1->data != NULL)
21892 {
21893 free(sfx1->data);
21894 }
21895
21896 if(sfx2->data == NULL)
21897 sfx1->data = NULL;
21898 else
21899 {
21900 // When quests are saved and loaded, data is written in words.
21901 // If the last byte is dropped, it'll cause the sound to end with
21902 // a click. It could simply be extended and padded with 0, but
21903 // that causes compatibility issues... So we'll cut off
21904 // the last byte and decrease the length.
21905
21906 int32_t len = (sfx1->bits==8?1:2)*(sfx1->stereo == 0 ? 1 : 2)*sfx1->len;
21907
21908 while(len%sizeof(word))
21909 {
21910 // sizeof(word) should be 2, so this doesn't really need
21911 // to be a loop, but what the heck.
21912 sfx1->len--;
21913 len = (sfx1->bits==8?1:2)*(sfx1->stereo == 0 ? 1 : 2)*sfx1->len;
21914 }
21915
21916 sfx1->data = malloc(len);
21917 memcpy(sfx1->data, sfx2->data, len);
21918 }
21919 }
21920
21921 bool confirmBox(const char *m1, const char *m2, const char *m3)
21922 {
21923 if(!m3)
21924 {
21925 if(!m2) m2 = "Are you sure?";
21926 else m3 = "Are you sure?";
21927 }
21928 return jwin_alert("Confirmation", m1, m2, m3, "Yes", "No", 'y', 'n', get_zc_font(font_lfont)) == 1;
21929 }
21930
21931 int32_t onSelectSFX()
21932 {
21933 SFXListerDialog(0).show();
21934 refresh(rMAP+rCOMBOS);
21935 return D_O_K;
21936 }
21937
21938 bool saveWAV(int32_t slot, const char *filename)
21939 {
21940 if (slot < 1 || slot >= 511 )
21941 return false;
21942
21943 if (customsfxdata[slot].data == NULL)
21944 return false;
21945
21946 std::ofstream ofs(filename, std::ios::binary);
21947 if (!ofs)
21948 return false;
21949 ofs.write("RIFF",4);
21950 uint32_t samplerate = customsfxdata[slot].freq;
21951 uint16_t channels = customsfxdata[slot].stereo ? 2 : 1;
21952 uint32_t datalen = customsfxdata[slot].len*channels*customsfxdata[slot].bits / 8;
21953 uint32_t size = 36 + datalen;
21954 ofs.write((char *)&size, 4);
21955 ofs.write("WAVE", 4);
21956 ofs.write("fmt ", 4);
21957 uint32_t fmtlen = 16;
21958 ofs.write((char *)&fmtlen, 4);
21959 uint16_t type = 1;
21960 ofs.write((char *)&type, 2);
21961 ofs.write((char *)&channels, 2);
21962 ofs.write((char *)&samplerate, 4);
21963 uint32_t bytespersec = samplerate*channels*customsfxdata[slot].bits / 8;
21964 ofs.write((char *)&bytespersec, 4);
21965 uint16_t blockalign = channels*customsfxdata[slot].bits / 8;
21966 ofs.write((char *)&blockalign, 2);
21967 uint16_t bitspersample = customsfxdata[slot].bits;
21968 ofs.write((char *)&bitspersample, 2);
21969 ofs.write("data", 4);
21970 ofs.write((char *)&datalen, 4);
21971 if (bitspersample == 8)
21972 {
21973 for (int32_t i = 0; i < (int32_t)customsfxdata[slot].len*channels; i++)
21974 {
21975 char data = ((char *)customsfxdata[slot].data)[i];
21976 data ^= 0x80;
21977 ofs.write(&data, 1);
21978 }
21979 }
21980 else if (bitspersample == 16)
21981 {
21982 for (int32_t i = 0; i < (int32_t)customsfxdata[slot].len*channels; i++)
21983 {
21984 uint16_t data = ((uint16_t *)customsfxdata[slot].data)[i];
21985 data ^= 0x8000;
21986 ofs.write((char *)&data, 2);
21987 }
21988 }
21989 else
21990 return false;
21991 return !!ofs;
21992 }
21993
21994 int32_t onEditSFX(int32_t index)
21995 {
21996 call_sfxdata_dialog(index);
21997 return D_O_K;
21998 }
21999
22000 int32_t onMapStyles()
22001 {
22002 call_mapstyles_dialog();
22003 return D_O_K;
22004 }
22005
22006 int32_t d_misccolors_old_proc(int32_t msg,DIALOG *d,int32_t c)
22007 {
22008 //these are here to bypass compiler warnings about unused arguments
22009 c=c;
22010
22011 if(msg==MSG_DRAW)
22012 {
22013 textout_ex(screen,font,"0123456789ABCDEF",d->x+8,d->y,d->fg,d->bg);
22014 textout_ex(screen,font,"0",d->x,d->y+8,d->fg,d->bg);
22015 textout_ex(screen,font,"1",d->x,d->y+16,d->fg,d->bg);
22016 textout_ex(screen,font,"5",d->x,d->y+24,d->fg,d->bg);
22017
22018 for(int32_t i=0; i<32; i++)
22019 {
22020 int32_t px2 = d->x+((i&15)<<3)+8;
22021 int32_t py2 = d->y+((i>>4)<<3)+8;
22022 rectfill(screen,px2,py2,px2+7,py2+7,i);
22023 }
22024
22025 for(int32_t i=0; i<16; i++)
22026 {
22027 int32_t px2 = d->x+(i<<3)+8;
22028 rectfill(screen,px2,d->y+24,px2+7,d->y+31,i+80);
22029 }
22030 }
22031
22032 return D_O_K;
22033 }
22034
22035 int32_t hexclicked=-1;
22036
22037 int32_t d_misccolors_hexedit_proc(int32_t msg,DIALOG *d,int32_t c)
22038 {
22039 switch(msg)
22040 {
22041 case MSG_GOTFOCUS:
22042 hexclicked=((int32_t)(size_t)(d->dp3))+20;
22043 break;
22044
22045 case MSG_LOSTFOCUS:
22046 hexclicked=-1;
22047 break;
22048 }
22049
22050 return d_hexedit_proc(msg,d,c);
22051 }
22052
22053
22054 int32_t d_misccolors_proc(int32_t msg,DIALOG *d,int32_t c);
22055
22056 static int32_t misccolor1_list[] =
22057 {
22058 // dialog control number
22059 4, 5, 6, 7, 8, 20, 21, 22, 23, 24, 36, 37, 38, 39, 40, -1
22060 };
22061
22062 static int32_t misccolor2_list[] =
22063 {
22064 // dialog control number
22065 9, 10, 11, 12, 13, 25, 26, 27, 28, 29, 41, 42, 43, 44, 45, -1
22066 };
22067
22068 static int32_t misccolor3_list[] =
22069 {
22070 // dialog control number
22071 14, 15, 16, 17, 18, 30, 31, 32, 33, 34, 46, 47, 48, 49, 50, -1
22072 };
22073
22074 static int32_t misccolor4_list[] =
22075 {
22076 19, 35, 51, 54, 55, 56, -1
22077 };
22078
22079 static TABPANEL misccolor_tabs[] =
22080 {
22081 // (text)
22082 { (char *)"1", D_SELECTED, misccolor1_list, 0, NULL },
22083 { (char *)"2", 0, misccolor2_list, 0, NULL },
22084 { (char *)"3", 0, misccolor3_list, 0, NULL },
22085 { (char *)"4", 0, misccolor4_list, 0, NULL },
22086 { NULL, 0, NULL, 0, NULL }
22087 };
22088
22089 int32_t d_misccolors_tab_proc(int32_t msg,DIALOG *d,int32_t c);
22090
22091 static DIALOG misccolors_dlg[] =
22092 {
22093 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
22094 12 { jwin_win_proc, 2, 21, 316, 197-23, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Misc Colors", NULL, NULL },
22095 // { jwin_frame_proc, 98-84+1+2, 52+8-6+4, 132, 100, vc(15), vc(1), 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
22096 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
22097 12 { d_misccolors_proc, 92-84+1+2, 44+8-6+4, 128+8, 96+8, vc(9), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
22098 //3
22099 12 { d_misccolors_tab_proc, 150+14-2+10-15, 60-14, 150-10+15, 144-20-10, jwin_pal[jcBOXFG], jwin_pal[jcBOX], 0, 0, 0, 0, (void *) misccolor_tabs, NULL, (void *)misccolors_dlg },
22100 //4
22101 12 { jwin_text_proc, 215-25-12-15, 76-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Text:", NULL, NULL },
22102 12 { jwin_text_proc, 215-25-12-15, 94-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Caption:", NULL, NULL },
22103 12 { jwin_text_proc, 215-25-12-15, 112-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Overworld Minmap:", NULL, NULL },
22104 12 { jwin_text_proc, 215-25-12-15, 130-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Minimap Background:", NULL, NULL },
22105 12 { jwin_text_proc, 215-25-12-15, 148-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Minimap Foreground 1:", NULL, NULL },
22106 12 { jwin_text_proc, 215-25-12-15, 76-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Minimap Foreground 2:", NULL, NULL },
22107 12 { jwin_text_proc, 215-25-12-15, 94-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "BS Minimap Dark:", NULL, NULL },
22108 12 { jwin_text_proc, 215-25-12-15, 112-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "BS Minimap Goal:", NULL, NULL },
22109 12 { jwin_text_proc, 215-25-12-15, 130-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Compass Mark (Light):", NULL, NULL },
22110 12 { jwin_text_proc, 215-25-12-15, 148-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Compass Mark (Dark):", NULL, NULL },
22111 12 { jwin_text_proc, 215-25-12-15, 76-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Subscreen Background:", NULL, NULL },
22112 12 { jwin_text_proc, 215-25-12-15, 94-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Subscreen Shadow:", NULL, NULL },
22113 12 { jwin_text_proc, 215-25-12-15, 112-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Triforce Frame:", NULL, NULL },
22114 12 { jwin_text_proc, 215-25-12-15, 130-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Big Map Background:", NULL, NULL },
22115 12 { jwin_text_proc, 215-25-12-15, 148-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Big Map Foreground:", NULL, NULL },
22116 12 { jwin_text_proc, 215-25-12-15, 76-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Hero's Position:", NULL, NULL },
22117
22118 //20
22119 12 { d_misccolors_hexedit_proc, 294-25+14+2, 76-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)0, },
22120 12 { d_misccolors_hexedit_proc, 294-25+14+2, 94-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)1, },
22121 12 { d_misccolors_hexedit_proc, 294-25+14+2, 112-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)2, },
22122 12 { d_misccolors_hexedit_proc, 294-25+14+2, 130-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)3, },
22123 12 { d_misccolors_hexedit_proc, 294-25+14+2, 148-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)4, },
22124 12 { d_misccolors_hexedit_proc, 294-25+14+2, 76-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)5, },
22125 12 { d_misccolors_hexedit_proc, 294-25+14+2, 94-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)6, },
22126 12 { d_misccolors_hexedit_proc, 294-25+14+2, 112-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)7, },
22127 12 { d_misccolors_hexedit_proc, 294-25+14+2, 130-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)8, },
22128 12 { d_misccolors_hexedit_proc, 294-25+14+2, 148-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)9, },
22129 12 { d_misccolors_hexedit_proc, 294-25+14+2, 76-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)10, },
22130 12 { d_misccolors_hexedit_proc, 294-25+14+2, 94-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)11, },
22131 12 { d_misccolors_hexedit_proc, 294-25+14+2, 112-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)12, },
22132 12 { d_misccolors_hexedit_proc, 294-25+14+2, 130-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)13, },
22133 12 { d_misccolors_hexedit_proc, 294-25+14+2, 148-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)14, },
22134 12 { d_misccolors_hexedit_proc, 294-25+14+2, 76-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)15, },
22135
22136 //36
22137 12 { jwin_text_proc, 283-25+14+2, 76-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22138 12 { jwin_text_proc, 283-25+14+2, 94-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22139 12 { jwin_text_proc, 283-25+14+2, 112-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22140 12 { jwin_text_proc, 283-25+14+2, 130-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22141 12 { jwin_text_proc, 283-25+14+2, 148-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22142 12 { jwin_text_proc, 283-25+14+2, 76-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22143 12 { jwin_text_proc, 283-25+14+2, 94-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22144 12 { jwin_text_proc, 283-25+14+2, 112-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22145 12 { jwin_text_proc, 283-25+14+2, 130-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22146 12 { jwin_text_proc, 283-25+14+2, 148-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22147 12 { jwin_text_proc, 283-25+14+2, 76-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22148 12 { jwin_text_proc, 283-25+14+2, 94-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22149 12 { jwin_text_proc, 283-25+14+2, 112-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22150 12 { jwin_text_proc, 283-25+14+2, 130-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22151 12 { jwin_text_proc, 283-25+14+2, 148-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22152 12 { jwin_text_proc, 283-25+14+2, 76-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22153
22154 //52
22155 12 { jwin_button_proc, 90, 190-20, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
22156 12 { jwin_button_proc, 170, 190-20, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
22157 12 { jwin_text_proc, 215-25-12-15, 94-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Message Text:", NULL, NULL },
22158 12 { d_misccolors_hexedit_proc, 294-25+14+2, 94-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)35, },
22159 12 { jwin_text_proc, 283-25+14+2, 94-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22160 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
22161 };
22162
22163 int32_t d_misccolors_tab_proc(int32_t msg,DIALOG *d,int32_t c)
22164 {
22165
22166 switch(msg)
22167 {
22168 case MSG_WANTFOCUS:
22169 return D_WANTFOCUS;
22170 break;
22171 }
22172
22173 return jwin_tab_proc(msg,d,c);
22174 }
22175
22176
22177 int32_t d_misccolors_proc(int32_t msg,DIALOG *d,int32_t c)
22178 {
22179 //these are here to bypass compiler warnings about unused arguments
22180 c=c;
22181 int32_t mul=12;
22182
22183 switch(msg)
22184 {
22185 case MSG_CLICK:
22186 if(hexclicked!=-1)
22187 {
22188 int32_t color_col=vbound(((gui_mouse_x()-d->x-8)/mul),0,15);
22189 int32_t color_row=vbound(((gui_mouse_y()-d->y-10)/mul),0,11);
22190 sprintf((char*)misccolors_dlg[hexclicked].dp,"%X%X",color_row,color_col);
22191 object_message(misccolors_dlg+hexclicked,MSG_DRAW,0);
22192 }
22193
22194 break;
22195
22196 case MSG_DRAW:
22197 for(int32_t i=0; i<10; i++)
22198 {
22199 textprintf_centre_ex(screen,font,d->x+8+4+(i*mul),d->y,jwin_pal[jcBOXFG],jwin_pal[jcBOX], "%d", i);
22200 }
22201
22202 for(int32_t i=0; i<6; i++)
22203 {
22204 textprintf_centre_ex(screen,font,d->x+8+4+((10+i)*mul),d->y,jwin_pal[jcBOXFG],jwin_pal[jcBOX], "%c", i+'A');
22205 }
22206
22207 for(int32_t i=0; i<10; i++)
22208 {
22209 textprintf_right_ex(screen,font,d->x+6,d->y+(i*mul)+10,jwin_pal[jcBOXFG],jwin_pal[jcBOX], "%d", i);
22210 }
22211
22212 for(int32_t i=0; i<2; i++)
22213 {
22214 textprintf_right_ex(screen,font,d->x+6,d->y+((i+10)*mul)+10,jwin_pal[jcBOXFG],jwin_pal[jcBOX], "%c", i+'A');
22215 }
22216
22217 jwin_draw_frame(screen,d->x+6,d->y+8,int32_t(132*1.5)-2,int32_t(100*1.5)-2,FR_DEEP);
22218
22219 for(int32_t i=0; i<192; i++)
22220 {
22221 int32_t px2 = d->x+int32_t(((i&15)<<3)*1.5)+8;
22222 int32_t py2 = d->y+int32_t(((i>>4)<<3)*1.5)+8+2;
22223 rectfill(screen,px2,py2,px2+(mul-1),py2+(mul-1),i);
22224 }
22225
22226 break;
22227 }
22228
22229 return D_O_K;
22230 }
22231
22232
22233 int32_t onMiscColors()
22234 {
22235 char buf[17][3];
22236 byte *si = &(QMisc.colors.text);
22237 misccolors_dlg[0].dp2=get_zc_font(font_lfont);
22238
22239 for(int32_t i=0; i<16; i++)
22240 {
22241 sprintf(buf[i],"%02X",*(si++));
22242 sprintf(buf[16], "%02X", QMisc.colors.msgtext);
22243 misccolors_dlg[i+20].dp = buf[i];
22244 misccolors_dlg[55].dp = buf[16];
22245 }
22246
22247 large_dialog(misccolors_dlg);
22248
22249 if(do_zqdialog(misccolors_dlg,0)==52)
22250 {
22251 saved=false;
22252 si = &(QMisc.colors.text);
22253
22254 for(int32_t i=0; i<16; i++)
22255 {
22256 *si = zc_xtoi(buf[i]);
22257 ++si;
22258 }
22259
22260 QMisc.colors.msgtext = zc_xtoi(buf[16]);
22261 }
22262
22263 return D_O_K;
22264 }
22265
22266 // **** Palette cycling ****
22267
22268 static int32_t palclk[3];
22269 static int32_t palpos[3];
22270
22271 32 void reset_pal_cycling()
22272 {
22273
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 32 times.
128 for(int32_t i=0; i<3; i++)
22274 96 palclk[i]=palpos[i]=0;
22275 32 }
22276
22277 void cycle_palette()
22278 {
22279 if(!get_qr(qr_FADE))
22280 return;
22281
22282 int32_t level = Map.CurrScr()->color;
22283 bool refreshpal = false;
22284
22285 for(int32_t i=0; i<3; i++)
22286 {
22287 palcycle c = QMisc.cycles[level][i];
22288
22289 if(c.count&0xF0)
22290 {
22291 if(++palclk[i] >= c.speed)
22292 {
22293 palclk[i]=0;
22294
22295 if(++palpos[i] >= (c.count>>4))
22296 palpos[i]=0;
22297
22298 byte *si = colordata + CSET(level*pdLEVEL+poFADE1+1+palpos[i])*3;
22299
22300 si += (c.first&15)*3;
22301
22302 for(int32_t col=c.first&15; col<=(c.count&15); col++)
22303 {
22304 RAMpal[CSET(c.first>>4)+col] = _RGB(si);
22305 si+=3;
22306 }
22307
22308 refreshpal = true;
22309 }
22310 }
22311 }
22312
22313 if(refreshpal)
22314 {
22315 rebuild_trans_table();
22316 zc_set_palette_range(RAMpal,0,192,false);
22317 }
22318 }
22319
22320
22321 void doHelp()
22322 {
22323 do_box_edit(helpstr, "ZQuest Help", true, true);
22324 }
22325
22326 int32_t onHelp()
22327 {
22328 restore_mouse();
22329 doHelp();
22330 return D_O_K;
22331 }
22332
22333 void doZstringshelp()
22334 {
22335 do_box_edit(zstringshelpstr, "ZStrings Help", true, true);
22336 }
22337
22338 int32_t onZstringshelp()
22339 {
22340 restore_mouse();
22341 doZstringshelp();
22342 return D_O_K;
22343 }
22344
22345 static DIALOG layerdata_dlg[] =
22346 {
22347 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
22348 { jwin_win_proc, 16-12, 20+32, 288+1+24, 200+1-32-16, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Layer Data", NULL, NULL },
22349 { jwin_button_proc, 170, 180, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
22350 { jwin_button_proc, 90, 180, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
22351 // 3
22352 { jwin_rtext_proc, 72, 88, 40, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Map:", NULL, NULL },
22353 { jwin_rtext_proc, 72, 88+18, 48, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Screen:", NULL, NULL },
22354 { jwin_rtext_proc, 72, 88+36, 56, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Transparent:", NULL, NULL },
22355 { jwin_ctext_proc, 89, 76, 8, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "1", NULL, NULL },
22356 { jwin_ctext_proc, 89+40, 76, 8, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "2", NULL, NULL },
22357 { jwin_ctext_proc, 89+80, 76, 8, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "3", NULL, NULL },
22358 { jwin_ctext_proc, 89+120, 76, 8, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "4", NULL, NULL },
22359 { jwin_ctext_proc, 89+160, 76, 8, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "5", NULL, NULL },
22360 { jwin_ctext_proc, 89+200, 76, 8, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "6", NULL, NULL },
22361
22362 //12
22363 { jwin_edit_proc, 76, 76+8, 32-6, 16, vc(12), vc(1), 0, 0, 3, 0, NULL, NULL, NULL },
22364 { d_hexedit_proc, 76, 76+18+8, 24-3, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
22365 { jwin_check_proc, 76, 76+40+8, 17, 9, vc(12), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
22366
22367 { jwin_edit_proc, 76+40, 76+8, 32-6, 16, vc(12), vc(1), 0, 0, 3, 0, NULL, NULL, NULL },
22368 { d_hexedit_proc, 76+40, 76+18+8, 24-3, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
22369 { jwin_check_proc, 76+40, 76+40+8, 17, 9, vc(12), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
22370
22371 { jwin_edit_proc, 76+80, 76+8, 32-6, 16, vc(12), vc(1), 0, 0, 3, 0, NULL, NULL, NULL },
22372 { d_hexedit_proc, 76+80, 76+18+8, 24-3, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
22373 { jwin_check_proc, 76+80, 76+40+8, 17, 9, vc(12), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
22374
22375 { jwin_edit_proc, 76+120, 76+8, 32-6, 16, vc(12), vc(1), 0, 0, 3, 0, NULL, NULL, NULL },
22376 { d_hexedit_proc, 76+120, 76+18+8, 24-3, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
22377 { jwin_check_proc, 76+120, 76+40+8, 17, 9, vc(12), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
22378
22379 { jwin_edit_proc, 76+160, 76+8, 32-6, 16, vc(12), vc(1), 0, 0, 3, 0, NULL, NULL, NULL },
22380 { d_hexedit_proc, 76+160, 76+18+8, 24-3, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
22381 { jwin_check_proc, 76+160, 76+40+8, 17, 9, vc(12), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
22382
22383 { jwin_edit_proc, 76+200, 76+8, 32-6, 16, vc(12), vc(1), 0, 0, 3, 0, NULL, NULL, NULL },
22384 { d_hexedit_proc, 76+200, 76+18+8, 24-3, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
22385 { jwin_check_proc, 76+200, 76+40+8, 17, 9, vc(12), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
22386
22387 //30
22388 { jwin_button_proc, 76, 76+40+18+8, 30, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Auto", NULL, NULL },
22389 { jwin_button_proc, 76+40, 76+40+18+8, 30, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Auto", NULL, NULL },
22390 { jwin_button_proc, 76+80, 76+40+18+8, 30, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Auto", NULL, NULL },
22391 { jwin_button_proc, 76+120, 76+40+18+8, 30, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Auto", NULL, NULL },
22392 { jwin_button_proc, 76+160, 76+40+18+8, 30, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Auto", NULL, NULL },
22393 { jwin_button_proc, 76+200, 76+40+18+8, 30, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Auto", NULL, NULL },
22394
22395 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
22396 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
22397
22398 };
22399
22400 int32_t edit_layers(mapscr* tempscr)
22401 {
22402 char buf[6][2][8];
22403 layerdata_dlg[0].dp2 = get_zc_font(font_lfont);
22404
22405 for(int32_t x=0; x<6; x++)
22406 {
22407 sprintf(buf[x][0],"%d",tempscr->layermap[x]);
22408 sprintf(buf[x][1],"%02X",tempscr->layerscreen[x]);
22409 }
22410
22411 for(int32_t x=0; x<6; x++)
22412 {
22413 for(int32_t y=0; y<2; y++)
22414 {
22415 layerdata_dlg[(x*3)+y+12].dp = buf[x][y];
22416 }
22417 }
22418
22419 for(int32_t x=0; x<6; x++)
22420 {
22421 layerdata_dlg[(x*3)+2+12].flags = (tempscr->layeropacity[x]<255) ? D_SELECTED : 0;
22422 }
22423
22424 large_dialog(layerdata_dlg);
22425
22426 int32_t ret=do_zqdialog(layerdata_dlg,0);
22427
22428 if(ret>=2)
22429 {
22430 for(int32_t x=0; x<6; x++)
22431 {
22432
22433 tempscr->layermap[x]=atoi(buf[x][0]);
22434
22435 if(tempscr->layermap[x]>map_count)
22436 {
22437 tempscr->layermap[x]=0;
22438 }
22439
22440 tempscr->layerscreen[x]=zc_xtoi(buf[x][1]);
22441
22442 if(zc_xtoi(buf[x][1])>=MAPSCRS)
22443 {
22444 tempscr->layerscreen[x]=0;
22445 }
22446
22447 // tempscr->layeropacity[x]=layerdata_dlg[(x*9)+8+19].flags & D_SELECTED ? 128:255;
22448 tempscr->layeropacity[x]=layerdata_dlg[(x*3)+2+12].flags & D_SELECTED ? 128:255;
22449 }
22450
22451 // } else if (ret>72&&ret<79) {
22452 // return (ret-72);
22453 }
22454
22455 return ret;
22456 }
22457
22458 static DIALOG autolayer_dlg[] =
22459 {
22460 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
22461 { jwin_win_proc, 64, 32+48, 192+1, 184+1-64, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Autolayer Setup", NULL, NULL },
22462 { jwin_text_proc, 76, 56+48, 136, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Map for layer ?: ", NULL, NULL },
22463 { jwin_edit_proc, 212, 56+48, 32, 16, vc(12), vc(1), 0, 0, 3, 0, NULL, NULL, NULL },
22464 { jwin_check_proc, 76, 56+18+48, 153, 8, vc(14), vc(1), 0, D_EXIT, 1, 0, (void *) "Only Blank Screens", NULL, NULL },
22465 { jwin_button_proc, 90, 188-12, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
22466
22467 //5
22468 { jwin_button_proc, 170, 188-12, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
22469 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F1, 0, (void *) onHelp, NULL, NULL },
22470 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
22471 { jwin_check_proc, 76, 56+28+48, 153, 8, vc(14), vc(1), 0, D_EXIT, 1, 0, (void *) "Only Blank Layers", NULL, NULL },
22472 { jwin_check_proc, 76, 56+38+48, 153, 8, vc(14), vc(1), 0, D_EXIT, 1, 0, (void *) "Overwrite Layers", NULL, NULL },
22473
22474 //10
22475 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
22476 };
22477 enum
22478 {
22479 autolyr_blankscreens,
22480 autolyr_blanklayers,
22481 autolyr_any
22482 };
22483 void autolayer(mapscr* tempscr, int32_t layer, int32_t al[6][3])
22484 {
22485 char tbuf[80],mlayer[80];
22486 autolayer_dlg[0].dp2=get_zc_font(font_lfont);
22487 sprintf(tbuf, "Map for layer %d: ", layer+1);
22488 autolayer_dlg[1].dp=tbuf;
22489 sprintf(mlayer, "%d", tempscr->layermap[layer]);
22490 autolayer_dlg[2].dp=mlayer;
22491
22492 large_dialog(autolayer_dlg);
22493 int ret, sel = 8, fl = autolyr_blanklayers;
22494 bool running = true;
22495 do
22496 {
22497 SETFLAG(autolayer_dlg[3].flags, D_SELECTED, sel==3);
22498 SETFLAG(autolayer_dlg[8].flags, D_SELECTED, sel==8);
22499 SETFLAG(autolayer_dlg[9].flags, D_SELECTED, sel==9);
22500 switch(ret=do_zqdialog(autolayer_dlg,0))
22501 {
22502 case 4: //OK
22503 {
22504 int32_t lmap=vbound(atoi(mlayer),0,Map.getMapCount());
22505 al[layer][0]=lmap;
22506 tempscr->layermap[layer]=lmap;
22507 tempscr->layerscreen[layer]=Map.getCurrScr();
22508 al[layer][1]=fl;
22509 al[layer][2]=1;
22510 running = false;
22511 break;
22512 }
22513 case 0: case 5: //cancel
22514 running = false;
22515 break;
22516 case 3:
22517 sel = ret;
22518 fl = autolyr_blankscreens;
22519 break;
22520 case 8:
22521 sel = ret;
22522 fl = autolyr_blanklayers;
22523 break;
22524 case 9:
22525 sel = ret;
22526 fl = autolyr_any;
22527 break;
22528 }
22529 }
22530 while(ret != 0 && ret != 4 && ret != 5);
22531 }
22532
22533 int32_t onLayers()
22534 {
22535 mapscr tempscr=*Map.CurrScr();
22536 int32_t al[6][3]; //autolayer[layer][0=map, 1=autolyr_ type, 2=bool go]
22537
22538 for(int32_t i=0; i<6; i++)
22539 {
22540 al[i][0]=tempscr.layermap[i];
22541 al[i][1]=0;
22542 al[i][2]=0;
22543 }
22544
22545 int32_t ret;
22546
22547 do
22548 {
22549 ret=edit_layers(&tempscr);
22550
22551 if(ret>2) //autolayer button
22552 {
22553 autolayer(&tempscr, ret-30, al);
22554 }
22555 }
22556 while(ret>2); //autolayer button
22557
22558 if(ret==2) //OK
22559 {
22560 saved=false;
22561 TheMaps[Map.getCurrMap()*MAPSCRS+Map.getCurrScr()]=tempscr;
22562
22563 for(int32_t i=0; i<6; i++)
22564 {
22565 int32_t tm=tempscr.layermap[i]-1;
22566 int32_t ts=tempscr.layerscreen[i];
22567
22568 if(al[i][2])
22569 {
22570 map_infos[Map.getCurrMap()].autolayers[i] = al[i][0];
22571 for(int32_t j=0; j<128; j++)
22572 {
22573 auto& curmapscr = TheMaps[Map.getCurrMap()*MAPSCRS+j];
22574 if(al[i][1] == autolyr_blankscreens && (curmapscr.valid&mVALID))
22575 continue;
22576 else if(al[i][1] == autolyr_blanklayers && curmapscr.layermap[i])
22577 continue;
22578
22579 curmapscr.layermap[i]=al[i][0];
22580 curmapscr.layerscreen[i]=al[i][0]?j:0;
22581 }
22582 }
22583 }
22584 }
22585
22586 // Check that the working layer wasn't just disabled
22587 if(CurrentLayer>0 && tempscr.layermap[CurrentLayer-1]==0)
22588 CurrentLayer=0;
22589
22590 return D_O_K;
22591 }
22592
22593
22594 char *itoa(int32_t i)
22595 {
22596 static char itoaret[500];
22597 sprintf(itoaret, "%d", i);
22598 return itoaret;
22599 }
22600
22601 22 void fps_callback()
22602 {
22603 22 lastfps=framecnt;
22604 22 framecnt=0;
22605 22 }
22606
22607 END_OF_FUNCTION(fps_callback)
22608
22609 //uint32_t col_diff[3*128];
22610 /*
22611 void bestfit_init(void)
22612 {
22613 int32_t i;
22614
22615 for (i=1; i<64; i++)
22616
22617 {
22618 int32_t k = i * i;
22619 col_diff[0 +i] = col_diff[0 +128-i] = k * (59 * 59);
22620 col_diff[128+i] = col_diff[128+128-i] = k * (30 * 30);
22621 col_diff[256+i] = col_diff[256+128-i] = k * (11 * 11);
22622 }
22623 }
22624 */
22625 21 void create_rgb_table2(RGB_MAP *table, AL_CONST PALETTE pal_8bit, void (*callback)(int32_t pos))
22626 {
22627 #define UNUSED 65535
22628 #define LAST 65532
22629
22630 // Allegro has been modified to use an 8 bit palette, but this method and RGB_MAP still use 6 bit.
22631 PALETTE pal;
22632
2/2
✓ Branch 0 taken 5376 times.
✓ Branch 1 taken 21 times.
5397 for (int i = 0; i < 256; i++)
22633 {
22634 5376 pal[i] = pal_8bit[i];
22635 5376 pal[i].r /= 4;
22636 5376 pal[i].g /= 4;
22637 5376 pal[i].b /= 4;
22638 5376 }
22639
22640 /* macro add adds to single linked list */
22641 #define add(i) (next[(i)] == UNUSED ? (next[(i)] = LAST, \
22642 (first != LAST ? (next[last] = (i)) : (first = (i))), \
22643 (last = (i))) : 0)
22644
22645 /* same but w/o checking for first element */
22646 #define add1(i) (next[(i)] == UNUSED ? (next[(i)] = LAST, \
22647 next[last] = (i), \
22648 (last = (i))) : 0)
22649 /* calculates distance between two colors */
22650 #define dist(a1, a2, a3, b1, b2, b3) \
22651 (col_diff[ ((a2) - (b2)) & 0x7F] + \
22652 (col_diff + 128)[((a1) - (b1)) & 0x7F] + \
22653 (col_diff + 256)[((a3) - (b3)) & 0x7F])
22654
22655 /* converts r,g,b to position in array and back */
22656 #define pos(r, g, b) \
22657 (((r) / 2) * 32 * 32 + ((g) / 2) * 32 + ((b) / 2))
22658
22659 #define depos(pal, r, g, b) \
22660 ((b) = ((pal) & 31) * 2, \
22661 (g) = (((pal) >> 5) & 31) * 2, \
22662 (r) = (((pal) >> 10) & 31) * 2)
22663
22664 /* is current color better than pal1? */
22665 #define better(r1, g1, b1, pal1) \
22666 (((int32_t)dist((r1), (g1), (b1), \
22667 (pal1).r, (pal1).g, (pal1).b)) > (int32_t)dist2)
22668
22669 /* checking of position */
22670 #define dopos(rp, gp, bp, ts) \
22671 if ((rp > -1 || r > 0) && (rp < 1 || r < 61) && \
22672 (gp > -1 || g > 0) && (gp < 1 || g < 61) && \
22673 (bp > -1 || b > 0) && (bp < 1 || b < 61)) \
22674 { \
22675 i = first + rp * 32 * 32 + gp * 32 + bp; \
22676 if (!data[i]) \
22677 { \
22678 data[i] = val; \
22679 add1(i); \
22680 } \
22681 else if ((ts) && (data[i] != val)) \
22682 { \
22683 dist2 = (rp ? (col_diff+128)[(r+2*rp-pal[val].r) & 0x7F] : r2) + \
22684 (gp ? (col_diff )[(g+2*gp-pal[val].g) & 0x7F] : g2) + \
22685 (bp ? (col_diff+256)[(b+2*bp-pal[val].b) & 0x7F] : b2); \
22686 if (better((r+2*rp), (g+2*gp), (b+2*bp), pal[data[i]])) \
22687 { \
22688 data[i] = val; \
22689 add1(i); \
22690 } \
22691 } \
22692 }
22693
22694 int32_t i, curr, r, g, b, val, dist2;
22695 uint32_t r2, g2, b2;
22696 uint16_t next[32*32*32];
22697 uint8_t *data;
22698 21 int32_t first = LAST;
22699 21 int32_t last = LAST;
22700 21 int32_t count = 0;
22701 21 int32_t cbcount = 0;
22702
22703 #define AVERAGE_COUNT 18000
22704
22705
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 10 times.
21 if(col_diff[1] == 0)
22706 11 bestfit_init();
22707
22708 21 memset(next, 255, sizeof(next));
22709 21 memset(table->data, 0, sizeof(char)*32*32*32);
22710
22711
22712 21 data = (uint8_t *)table->data;
22713
22714 /* add starting seeds for floodfill */
22715
2/2
✓ Branch 0 taken 5355 times.
✓ Branch 1 taken 21 times.
5376 for(i=1; i<PAL_SIZE; i++)
22716 {
22717 5355 curr = pos(pal[i].r, pal[i].g, pal[i].b);
22718
22719
2/2
✓ Branch 0 taken 4053 times.
✓ Branch 1 taken 1302 times.
5355 if(next[curr] == UNUSED)
22720 {
22721 1302 data[curr] = i;
22722
3/4
✓ Branch 0 taken 1302 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1281 times.
✓ Branch 3 taken 21 times.
1302 add(curr);
22723 1302 }
22724 5355 }
22725
22726 /* main floodfill: two versions of loop for faster growing in blue axis */
22727 // while (first != LAST) {
22728
2/2
✓ Branch 0 taken 450575 times.
✓ Branch 1 taken 21 times.
450596 while(first < LAST)
22729 {
22730 450575 depos(first, r, g, b);
22731
22732 /* calculate distance of current color */
22733 450575 val = data[first];
22734 450575 r2 = (col_diff+128)[((pal[val].r)-(r)) & 0x7F];
22735 450575 g2 = (col_diff)[((pal[val].g)-(g)) & 0x7F];
22736 450575 b2 = (col_diff+256)[((pal[val].b)-(b)) & 0x7F];
22737
22738 /* try to grow to all directions */
22739 #ifdef _MSC_VER
22740 #pragma warning(disable:4127)
22741 #endif
22742
11/12
✓ Branch 0 taken 14797 times.
✓ Branch 1 taken 435778 times.
✓ Branch 2 taken 418414 times.
✓ Branch 3 taken 17364 times.
✓ Branch 4 taken 17364 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 349903 times.
✓ Branch 7 taken 68511 times.
✓ Branch 8 taken 19107 times.
✓ Branch 9 taken 49404 times.
✓ Branch 10 taken 30562 times.
✓ Branch 11 taken 18842 times.
868989 dopos(0, 0, 1, 1);
22743
11/12
✓ Branch 0 taken 13307 times.
✓ Branch 1 taken 437268 times.
✓ Branch 2 taken 421926 times.
✓ Branch 3 taken 15342 times.
✓ Branch 4 taken 15342 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 367287 times.
✓ Branch 7 taken 54639 times.
✓ Branch 8 taken 21549 times.
✓ Branch 9 taken 33090 times.
✓ Branch 10 taken 21770 times.
✓ Branch 11 taken 11320 times.
872501 dopos(0, 0,-1, 1);
22744
11/12
✓ Branch 0 taken 14382 times.
✓ Branch 1 taken 436193 times.
✓ Branch 2 taken 424908 times.
✓ Branch 3 taken 11285 times.
✓ Branch 4 taken 11285 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 347042 times.
✓ Branch 7 taken 77866 times.
✓ Branch 8 taken 50354 times.
✓ Branch 9 taken 27512 times.
✓ Branch 10 taken 17286 times.
✓ Branch 11 taken 10226 times.
875483 dopos(1, 0, 0, 1);
22745
11/12
✓ Branch 0 taken 14499 times.
✓ Branch 1 taken 436076 times.
✓ Branch 2 taken 424084 times.
✓ Branch 3 taken 11992 times.
✓ Branch 4 taken 11992 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 349660 times.
✓ Branch 7 taken 74424 times.
✓ Branch 8 taken 49118 times.
✓ Branch 9 taken 25306 times.
✓ Branch 10 taken 16008 times.
✓ Branch 11 taken 9298 times.
874659 dopos(-1, 0, 0, 1);
22746
11/12
✓ Branch 0 taken 14539 times.
✓ Branch 1 taken 436036 times.
✓ Branch 2 taken 391471 times.
✓ Branch 3 taken 44565 times.
✓ Branch 4 taken 44565 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 290643 times.
✓ Branch 7 taken 100828 times.
✓ Branch 8 taken 83046 times.
✓ Branch 9 taken 17782 times.
✓ Branch 10 taken 11492 times.
✓ Branch 11 taken 6290 times.
842046 dopos(0, 1, 0, 1);
22747
11/12
✓ Branch 0 taken 13124 times.
✓ Branch 1 taken 437451 times.
✓ Branch 2 taken 399232 times.
✓ Branch 3 taken 38219 times.
✓ Branch 4 taken 38219 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 299384 times.
✓ Branch 7 taken 99848 times.
✓ Branch 8 taken 85123 times.
✓ Branch 9 taken 14725 times.
✓ Branch 10 taken 9189 times.
✓ Branch 11 taken 5536 times.
849807 dopos(0,-1, 0, 1);
22748 #ifdef _MSC_VER
22749 #pragma warning(default:4127)
22750 #endif
22751
22752 /* faster growing of blue direction */
22753
4/4
✓ Branch 0 taken 437268 times.
✓ Branch 1 taken 13307 times.
✓ Branch 2 taken 21549 times.
✓ Branch 3 taken 415719 times.
450575 if((b > 0) && (data[first-1] == val))
22754 {
22755 415719 b -= 2;
22756 415719 first--;
22757 415719 b2 = (col_diff+256)[((pal[val].b)-(b)) & 0x7F];
22758
22759 #ifdef _MSC_VER
22760 #pragma warning(disable:4127)
22761 #endif
22762
5/6
✓ Branch 0 taken 13508 times.
✓ Branch 1 taken 402211 times.
✓ Branch 2 taken 366059 times.
✓ Branch 3 taken 36152 times.
✓ Branch 4 taken 36152 times.
✗ Branch 5 not taken.
781778 dopos(-1, 0, 0, 0);
22763
5/6
✓ Branch 0 taken 13364 times.
✓ Branch 1 taken 402355 times.
✓ Branch 2 taken 365610 times.
✓ Branch 3 taken 36745 times.
✓ Branch 4 taken 36745 times.
✗ Branch 5 not taken.
781329 dopos(1, 0, 0, 0);
22764
5/6
✓ Branch 0 taken 12197 times.
✓ Branch 1 taken 403522 times.
✓ Branch 2 taken 355860 times.
✓ Branch 3 taken 47662 times.
✓ Branch 4 taken 47662 times.
✗ Branch 5 not taken.
771579 dopos(0,-1, 0, 0);
22765
5/6
✓ Branch 0 taken 13551 times.
✓ Branch 1 taken 402168 times.
✓ Branch 2 taken 336590 times.
✓ Branch 3 taken 65578 times.
✓ Branch 4 taken 65578 times.
✗ Branch 5 not taken.
752309 dopos(0, 1, 0, 0);
22766 #ifdef _MSC_VER
22767 #pragma warning(default:4127)
22768 #endif
22769
22770 415719 first++;
22771 415719 }
22772
22773 /* get next from list */
22774 450575 i = first;
22775 450575 first = next[first];
22776 450575 next[i] = UNUSED;
22777
22778 /* second version of loop */
22779 // if (first != LAST) {
22780
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 450564 times.
450575 if(first < LAST)
22781 {
22782
22783 450564 depos(first, r, g, b);
22784
22785 450564 val = data[first];
22786 450564 r2 = (col_diff+128)[((pal[val].r)-(r)) & 0x7F];
22787 450564 g2 = (col_diff)[((pal[val].g)-(g)) & 0x7F];
22788 450564 b2 = (col_diff+256)[((pal[val].b)-(b)) & 0x7F];
22789
22790 #ifdef _MSC_VER
22791 #pragma warning(disable:4127)
22792 #endif
22793
11/12
✓ Branch 0 taken 14370 times.
✓ Branch 1 taken 436194 times.
✓ Branch 2 taken 415857 times.
✓ Branch 3 taken 20337 times.
✓ Branch 4 taken 20337 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 347408 times.
✓ Branch 7 taken 68449 times.
✓ Branch 8 taken 19063 times.
✓ Branch 9 taken 49386 times.
✓ Branch 10 taken 30486 times.
✓ Branch 11 taken 18900 times.
866421 dopos(0, 0, 1, 1);
22794
11/12
✓ Branch 0 taken 13244 times.
✓ Branch 1 taken 437320 times.
✓ Branch 2 taken 424306 times.
✓ Branch 3 taken 13014 times.
✓ Branch 4 taken 13014 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 369421 times.
✓ Branch 7 taken 54885 times.
✓ Branch 8 taken 21923 times.
✓ Branch 9 taken 32962 times.
✓ Branch 10 taken 21778 times.
✓ Branch 11 taken 11184 times.
874870 dopos(0, 0,-1, 1);
22795
11/12
✓ Branch 0 taken 14583 times.
✓ Branch 1 taken 435981 times.
✓ Branch 2 taken 424300 times.
✓ Branch 3 taken 11681 times.
✓ Branch 4 taken 11681 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 346291 times.
✓ Branch 7 taken 78009 times.
✓ Branch 8 taken 50641 times.
✓ Branch 9 taken 27368 times.
✓ Branch 10 taken 17229 times.
✓ Branch 11 taken 10139 times.
874864 dopos(1, 0, 0, 1);
22796
11/12
✓ Branch 0 taken 14345 times.
✓ Branch 1 taken 436219 times.
✓ Branch 2 taken 424380 times.
✓ Branch 3 taken 11839 times.
✓ Branch 4 taken 11839 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 349785 times.
✓ Branch 7 taken 74595 times.
✓ Branch 8 taken 49492 times.
✓ Branch 9 taken 25103 times.
✓ Branch 10 taken 16289 times.
✓ Branch 11 taken 8814 times.
874944 dopos(-1, 0, 0, 1);
22797
11/12
✓ Branch 0 taken 14476 times.
✓ Branch 1 taken 436088 times.
✓ Branch 2 taken 392433 times.
✓ Branch 3 taken 43655 times.
✓ Branch 4 taken 43655 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 292163 times.
✓ Branch 7 taken 100270 times.
✓ Branch 8 taken 82655 times.
✓ Branch 9 taken 17615 times.
✓ Branch 10 taken 11555 times.
✓ Branch 11 taken 6060 times.
842997 dopos(0, 1, 0, 1);
22798
11/12
✓ Branch 0 taken 13010 times.
✓ Branch 1 taken 437554 times.
✓ Branch 2 taken 399976 times.
✓ Branch 3 taken 37578 times.
✓ Branch 4 taken 37578 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 299995 times.
✓ Branch 7 taken 99981 times.
✓ Branch 8 taken 85368 times.
✓ Branch 9 taken 14613 times.
✓ Branch 10 taken 9367 times.
✓ Branch 11 taken 5246 times.
850540 dopos(0,-1, 0, 1);
22799 #ifdef _MSC_VER
22800 #pragma warning(default:4127)
22801 #endif
22802
22803
4/4
✓ Branch 0 taken 436194 times.
✓ Branch 1 taken 14370 times.
✓ Branch 2 taken 19063 times.
✓ Branch 3 taken 417131 times.
450564 if((b < 61) && (data[first + 1] == val))
22804 {
22805 417131 b += 2;
22806 417131 first++;
22807 417131 b2 = (col_diff+256)[((pal[val].b)-(b)) & 0x7f];
22808 #ifdef _MSC_VER
22809 #pragma warning(disable:4127)
22810 #endif
22811
5/6
✓ Branch 0 taken 13397 times.
✓ Branch 1 taken 403734 times.
✓ Branch 2 taken 361902 times.
✓ Branch 3 taken 41832 times.
✓ Branch 4 taken 41832 times.
✗ Branch 5 not taken.
779033 dopos(-1, 0, 0, 0);
22812
5/6
✓ Branch 0 taken 13497 times.
✓ Branch 1 taken 403634 times.
✓ Branch 2 taken 354721 times.
✓ Branch 3 taken 48913 times.
✓ Branch 4 taken 48913 times.
✗ Branch 5 not taken.
771852 dopos(1, 0, 0, 0);
22813
5/6
✓ Branch 0 taken 12034 times.
✓ Branch 1 taken 405097 times.
✓ Branch 2 taken 338219 times.
✓ Branch 3 taken 66878 times.
✓ Branch 4 taken 66878 times.
✗ Branch 5 not taken.
755350 dopos(0,-1, 0, 0);
22814
5/6
✓ Branch 0 taken 13617 times.
✓ Branch 1 taken 403514 times.
✓ Branch 2 taken 337319 times.
✓ Branch 3 taken 66195 times.
✓ Branch 4 taken 66195 times.
✗ Branch 5 not taken.
754450 dopos(0, 1, 0, 0);
22815 #ifdef _MSC_VER
22816 #pragma warning(default:4127)
22817 #endif
22818
22819 417131 first--;
22820 417131 }
22821
22822 450564 i = first;
22823 450564 first = next[first];
22824 450564 next[i] = UNUSED;
22825 450564 }
22826
22827 450575 count++;
22828
22829
2/2
✓ Branch 0 taken 445178 times.
✓ Branch 1 taken 5397 times.
450575 if(count == (cbcount+1)*AVERAGE_COUNT/256)
22830 {
22831
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 5376 times.
5397 if(cbcount < 256)
22832 {
22833
1/2
✓ Branch 0 taken 5376 times.
✗ Branch 1 not taken.
5376 if(callback)
22834 callback(cbcount);
22835
22836 5376 cbcount++;
22837 5376 }
22838 5397 }
22839
22840 }
22841
22842 /* only the transparent (pink) color can be mapped to index 0 */
22843
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
21 if((pal[0].r == 63) && (pal[0].g == 0) && (pal[0].b == 63))
22844 table->data[31][0][31] = 0;
22845
22846
1/2
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
21 if(callback)
22847 while(cbcount < 256)
22848 callback(cbcount++);
22849 21 }
22850
22851 21 void rebuild_trans_table()
22852 {
22853 21 create_rgb_table2(&zq_rgb_table, RAMpal, NULL);
22854 21 create_zc_trans_table(&trans_table, RAMpal, 128, 128, 128);
22855 21 memcpy(&trans_table2, &trans_table, sizeof(COLOR_MAP));
22856
22857
2/2
✓ Branch 0 taken 5376 times.
✓ Branch 1 taken 21 times.
5397 for(int32_t q=0; q<PAL_SIZE; q++)
22858 {
22859 5376 trans_table2.data[0][q] = q;
22860 5376 trans_table2.data[q][q] = q;
22861 5376 }
22862 21 }
22863
22864 int32_t isFullScreen()
22865 {
22866 return !is_windowed_mode();
22867 }
22868
22869 void hit_close_button()
22870 {
22871 close_button_quit=true;
22872 return;
22873 }
22874
22875 extern bool dirty_screen;
22876
22877 void anim_hw_screen(bool force)
22878 {
22879 // if (force || myvsync)
22880 {
22881 ++cpoolbrush_index;
22882
22883 if(prv_mode)
22884 {
22885 if(Map.get_prvtime())
22886 {
22887 Map.set_prvtime(Map.get_prvtime()-1);
22888
22889 if(!Map.get_prvtime())
22890 {
22891 prv_warp=1;
22892 }
22893 }
22894 }
22895 if(AnimationOn)
22896 {
22897 animate_combos();
22898 update_freeform_combos();
22899 }
22900
22901 if(CycleOn)
22902 cycle_palette();
22903
22904 animate_coords();
22905 update_hw_screen();
22906 }
22907 }
22908
22909 void custom_vsync()
22910 {
22911 anim_hw_screen(true);
22912 }
22913
22914 void switch_out()
22915 {
22916 zcmusic_pause(zcmusic, ZCM_PAUSE);
22917 zc_midi_pause();
22918 }
22919
22920 void switch_in()
22921 {
22922 if(exiting_program)
22923 return;
22924 zcmusic_pause(zcmusic, ZCM_RESUME);
22925 zc_midi_resume();
22926 }
22927
22928 void Z_eventlog(const char *format,...)
22929 {
22930 format=format; //to prevent a compiler warning
22931 }
22932
22933 int32_t get_currdmap()
22934 {
22935 return zinit.start_dmap;
22936 }
22937
22938 int32_t get_dlevel()
22939 {
22940 return DMaps[zinit.start_dmap].level;
22941 }
22942
22943 int32_t get_currscr()
22944 {
22945 return Map.getCurrScr();
22946 }
22947
22948 int32_t get_currmap()
22949 {
22950 return Map.getCurrMap();
22951 }
22952
22953 int32_t get_homescr()
22954 {
22955 return DMaps[zinit.start_dmap].cont;
22956 }
22957
22958 int get_screen_for_world_xy(int x, int y)
22959 {
22960 return -1;
22961 }
22962
22963 int current_item(int item_type, bool checkmagic, bool jinx_check, bool check_bunny)
22964 {
22965 //TODO remove as special case?? -DD
22966 if(item_type==itype_shield)
22967 {
22968 return 2;
22969 }
22970
22971 int id = current_item_id(item_type, checkmagic, jinx_check, check_bunny);
22972 return id > -1 ? itemsbuf[id].level : 0;
22973 }
22974
22975 int current_item_power(int itemtype, bool checkmagic, bool jinx_check, bool check_bunny)
22976 {
22977 if (game)
22978 {
22979 int result = current_item_id(itemtype, checkmagic, jinx_check, check_bunny);
22980 return (result<0) ? 0 : itemsbuf[result].power;
22981 }
22982 return 1;
22983 }
22984
22985 int32_t current_item_id(int32_t itemtype, bool, bool, bool)
22986 {
22987 if (game)
22988 {
22989 int32_t result = -1;
22990 int32_t highestlevel = -1;
22991
22992 for (int32_t i = 0; i < MAXITEMS; i++)
22993 {
22994 if ((zq_ignore_item_ownership || game->get_item(i)) && itemsbuf[i].type == itemtype)
22995 {
22996 if (itemsbuf[i].level >= highestlevel)
22997 {
22998 highestlevel = itemsbuf[i].level;
22999 result = i;
23000 }
23001 }
23002 }
23003 return result;
23004 }
23005 for(int32_t i=0; i<MAXITEMS; i++)
23006 {
23007 if(itemsbuf[i].type==itemtype)
23008 return i;
23009 }
23010
23011 return -1;
23012 }
23013
23014
23015 bool can_use_item(int32_t item_type, int32_t item)
23016 {
23017 //these are here to bypass compiler warnings about unused arguments
23018 item_type=item_type;
23019 item=item;
23020
23021 return true;
23022 }
23023
23024 bool has_item(int32_t item_type, int32_t it)
23025 {
23026 //these are here to bypass compiler warnings about unused arguments
23027 item_type=item_type;
23028 it=it;
23029
23030 return true;
23031 }
23032
23033 int32_t get_bmaps(int32_t si)
23034 {
23035 //these are here to bypass compiler warnings about unused arguments
23036 si=si;
23037
23038 return 255;
23039 }
23040
23041 bool no_subscreen()
23042 {
23043 return false;
23044 }
23045
23046 12 static void allocate_crap()
23047 {
23048 12 filepath=(char*)malloc(2048);
23049 12 datapath=(char*)malloc(2048);
23050 12 midipath=(char*)malloc(2048);
23051 12 imagepath=(char*)malloc(2048);
23052 12 tmusicpath=(char*)malloc(2048);
23053 12 last_timed_save=(char*)malloc(2048);
23054
23055
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!filepath || !datapath || !imagepath || !midipath || !tmusicpath || !last_timed_save)
23056 {
23057 Z_error_fatal("Error: no memory for file paths!");
23058 }
23059
23060
23061 12 customtunes = (zctune*)malloc(sizeof(zctune)*MAXCUSTOMMIDIS_ZQ);
23062 12 memset(customtunes, 0, sizeof(zctune)*MAXCUSTOMMIDIS_ZQ);
23063
23064
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXCUSTOMMIDIS_ZQ; ++i)
23065 {
23066 3072 customtunes[i].data=NULL;
23067 3072 }
23068
23069
2/2
✓ Branch 0 taken 3024 times.
✓ Branch 1 taken 12 times.
3036 for(int32_t i=0; i<MAXCUSTOMTUNES; i++)
23070 {
23071 3024 midi_string[i+4]=customtunes[i].title;
23072 3024 screen_midi_string[i+5]=customtunes[i].title;
23073 3024 }
23074
23075
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<WAV_COUNT; i++)
23076 {
23077
1/4
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3072 if(sfx_string[i]!=NULL) delete sfx_string[i];
23078 3072 customsfxdata[i].data=NULL;
23079 3072 sfx_string[i] = new char[36];
23080 3072 memset(sfx_string[i], 0, 36);
23081 3072 }
23082
23083
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXWPNS; i++)
23084 {
23085
1/4
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3072 if(weapon_string[i]!=NULL) delete weapon_string[i];
23086 3072 weapon_string[i] = new char[64];
23087 3072 memset(weapon_string[i], 0, 64);
23088 3072 }
23089
23090
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXITEMS; i++)
23091 {
23092
1/4
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3072 if(item_string[i]!=NULL) delete item_string[i];
23093 3072 item_string[i] = new char[64];
23094 3072 memset(item_string[i], 0, 64);
23095 3072 }
23096
23097
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<eMAXGUYS; i++)
23098 {
23099
1/4
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6144 if(guy_string[i]!=NULL) delete guy_string[i];
23100 6144 guy_string[i] = new char[64];
23101 6144 memset(guy_string[i], 0, 64);
23102 6144 }
23103
23104
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
23105 {
23106
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6144 times.
6144 delete ffscripts[i];
23107
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 ffscripts[i] = new script_data(ScriptType::FFC, i);
23108 6144 }
23109
23110
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
23111 {
23112
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 delete itemscripts[i];
23113
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 itemscripts[i] = new script_data(ScriptType::Item, i);
23114 3072 }
23115
23116
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
23117 {
23118
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 delete guyscripts[i];
23119
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 guyscripts[i] = new script_data(ScriptType::NPC, i);
23120 3072 }
23121
23122
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
23123 {
23124
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 delete screenscripts[i];
23125
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 screenscripts[i] = new script_data(ScriptType::Screen, i);
23126 3072 }
23127
23128
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(int32_t i=0; i<NUMSCRIPTGLOBAL; i++)
23129 {
23130
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 96 times.
96 delete globalscripts[i];
23131
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 globalscripts[i] = new script_data(ScriptType::Global, i);
23132 96 }
23133
23134
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 12 times.
72 for(int32_t i=0; i<NUMSCRIPTHERO; i++)
23135 {
23136
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 delete playerscripts[i];
23137
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 playerscripts[i] = new script_data(ScriptType::Hero, i);
23138 60 }
23139
23140
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
23141 {
23142
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 delete lwpnscripts[i];
23143
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 lwpnscripts[i] = new script_data(ScriptType::Lwpn, i);
23144 3072 }
23145
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
23146 {
23147
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3072 times.
3072 delete ewpnscripts[i];
23148
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 ewpnscripts[i] = new script_data(ScriptType::Ewpn, i);
23149 3072 }
23150
23151
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
23152 {
23153
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 delete dmapscripts[i];
23154
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 dmapscripts[i] = new script_data(ScriptType::DMap, i);
23155 3072 }
23156
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
23157 {
23158
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 delete itemspritescripts[i];
23159
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 itemspritescripts[i] = new script_data(ScriptType::ItemSprite, i);
23160 3072 }
23161
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
23162 {
23163
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 delete comboscripts[i];
23164
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 comboscripts[i] = new script_data(ScriptType::Combo, i);
23165 6144 }
23166
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSGENERIC; i++)
23167 {
23168
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 delete genericscripts[i];
23169
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 genericscripts[i] = new script_data(ScriptType::Generic, i);
23170 6144 }
23171
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
23172 {
23173
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3072 times.
3072 delete subscreenscripts[i];
23174
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 subscreenscripts[i] = new script_data(ScriptType::EngineSubscreen, i);
23175 3072 }
23176 12 }
23177
23178 static void handle_sentry_tags()
23179 {
23180 static bool sentry_first_time = true;
23181
23182 static MapCursor sentry_last_map_cursor;
23183 if (Map.getCursor() != sentry_last_map_cursor || sentry_first_time)
23184 {
23185 sentry_last_map_cursor = Map.getCursor();
23186 zapp_reporting_set_tag("cursor.map", sentry_last_map_cursor.map);
23187 zapp_reporting_set_tag("cursor.screen", sentry_last_map_cursor.screen);
23188 zapp_reporting_set_tag("cursor.viewscr", sentry_last_map_cursor.viewscr);
23189 zapp_reporting_set_tag("cursor.size", sentry_last_map_cursor.size);
23190 }
23191
23192 static bool sentry_last_is_compact;
23193 if (is_compact != sentry_last_is_compact || sentry_first_time)
23194 {
23195 sentry_last_is_compact = is_compact;
23196 zapp_reporting_set_tag("compact", sentry_last_is_compact);
23197 }
23198
23199 sentry_first_time = false;
23200 }
23201
23202 // Removes the top layer encoding from a quest file. See open_quest_file.
23203 // This has zero impact on the contents of the quest file. There should be no way for this to
23204 // break anything.
23205 static void do_unencrypt_qst_command(const char* input_filename, const char* output_filename)
23206 {
23207 // If the file is already an unencrypted packfile, there's nothing to do.
23208 PACKFILE* pf_check = pack_fopen_password(input_filename, F_READ_PACKED, "");
23209 pack_fclose(pf_check);
23210 if (pf_check) return;
23211
23212 int32_t error;
23213 PACKFILE* pf = open_quest_file(&error, input_filename, false);
23214 PACKFILE* pf2 = pack_fopen_password(output_filename, F_WRITE_PACKED, "");
23215 int c;
23216 while ((c = pack_getc(pf)) != EOF)
23217 {
23218 pack_putc(c, pf2);
23219 }
23220 pack_fclose(pf);
23221 pack_fclose(pf2);
23222 clear_quest_tmpfile();
23223 }
23224
23225 // This will remove the PACKFILE compression. Incidentally, it also removes the top encoding layer.
23226 static void do_uncompress_qst_command(const char* input_filename, const char* output_filename)
23227 {
23228 auto unencrypted_result = try_open_maybe_legacy_encoded_file(input_filename, ENC_STR, nullptr, QH_NEWIDSTR, QH_IDSTR);
23229 if (unencrypted_result.not_found)
23230 {
23231 printf("qst not found\n");
23232 zq_exit(1);
23233 }
23234 if (!unencrypted_result.compressed && !unencrypted_result.encrypted)
23235 {
23236 // If the file is already an uncompressed file, there's nothing to do but copy it.
23237 fs::copy(input_filename, output_filename);
23238 return;
23239 }
23240
23241 pack_fclose(unencrypted_result.decoded_pf);
23242
23243 int32_t error;
23244 PACKFILE* pf = open_quest_file(&error, input_filename, false);
23245 PACKFILE* pf2 = pack_fopen_password(output_filename, F_WRITE, "");
23246 int c;
23247 while ((c = pack_getc(pf)) != EOF)
23248 {
23249 pack_putc(c, pf2);
23250 }
23251 pack_fclose(pf);
23252 pack_fclose(pf2);
23253 clear_quest_tmpfile();
23254 }
23255
23256 // Copy a quest file by loading and resaving, exactly like if the user did it in the UI.
23257 // Note there could be changes introduced in the loading or saving functions. These are
23258 // typically for compatability, but could possibly be a source of bugs.
23259 3 static void do_copy_qst_command(const char* input_filename, const char* output_filename)
23260 {
23261 3 set_headless_mode();
23262
23263 // We need to init some stuff before loading a quest file will work.
23264 3 int fake_errno = 0;
23265 3 allegro_errno = &fake_errno;
23266 3 get_qst_buffers();
23267
23268 3 int ret = load_quest(input_filename, false);
23269
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (ret)
23270 {
23271 zq_exit(ret);
23272 }
23273
23274 3 ret = save_quest(output_filename, false);
23275 3 zq_exit(ret);
23276 3 }
23277
23278 int32_t Awpn=-1, Bwpn=-1, Xwpn = -1, Ywpn = -1;
23279 84 sprite_list guys, items, Ewpns, Lwpns, chainlinks, decorations, portals;
23280 int32_t exittimer = 10000, exittimer2 = 100;
23281
23282 1 static bool partial_load_test(const char* test_dir)
23283 {
23284
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 auto classic_path = fs::path(test_dir) / "replays/classic_1st/classic_1st.qst";
23285
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 int ret = load_quest(classic_path.string().c_str(), false);
23286
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (ret)
23287 {
23288 printf("failed to load classic_1st.qst: ret == %d\n", ret);
23289 return false;
23290 }
23291
23292 1 int cont = DMaps[0].cont;
23293
23294 // Skip same stuff as used in zq_tiles.cpp for grabbing tiles from a qst.
23295 byte skip_flags[4];
23296
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 26 times.
27 for (int i=0; i<skip_max; ++i)
23297
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 set_bit(skip_flags,i,1);
23298
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 set_bit(skip_flags,skip_tiles,0);
23299
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 set_bit(skip_flags,skip_header,0);
23300 1 zquestheader tempheader{};
23301
3/6
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 auto ptux_path = fs::path(test_dir) / "quests/PTUX.qst";
23302
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 ret = loadquest(ptux_path.string().c_str(), &tempheader, &QMisc, customtunes, false, skip_flags);
23303
23304
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (ret)
23305 {
23306 printf("failed to load PTUX.qst: ret == %d\n", ret);
23307 return false;
23308 }
23309
23310
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (DMaps[0].cont != cont)
23311 {
23312 printf("unexpected modification: DMaps[0].cont == %d, should be %d\n", DMaps[0].cont, cont);
23313 return false;
23314 }
23315
23316 // TODO should run replay. Currently, resaving classic_1st.qst fails its replay (see test_save in test_zeditor.py)
23317
23318 1 return true;
23319 1 }
23320
23321 template <typename ...Params>
23322 [[noreturn]] void FatalConsole(const char *format, Params&&... params)
23323 {
23324 FFCore.ZScriptConsole(CConsoleLoggerEx::COLOR_RED|CConsoleLoggerEx::COLOR_INTENSITY|CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"");
23325 Z_error_fatal(format, std::forward<Params>(params)...);
23326 }
23327
23328 40 static BITMAP* load_asset_bmp(const char* path)
23329 {
23330 40 BITMAP* bmp = load_bmp(path, nullptr);
23331
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 if (!bmp)
23332 Z_error_fatal("Failed to load required asset: %s\n", path);
23333 40 return bmp;
23334 }
23335
23336 8 static void load_asset_pal(PALETTE pal, const char* path)
23337 {
23338 8 BITMAP* bmp = load_bmp(path, pal);
23339
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (!bmp)
23340 Z_error_fatal("Failed to load required asset: %s\n", path);
23341 8 }
23342
23343 8 static MIDI* load_asset_midi(const char* path)
23344 {
23345 8 MIDI* midi = load_midi(path);
23346
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (!midi)
23347 Z_error_fatal("Failed to load required asset: %s\n", path);
23348 8 return midi;
23349 }
23350
23351 BITMAP* asset_icons_bmp;
23352 BITMAP* asset_engravings_bmp;
23353 BITMAP* asset_mouse_bmp;
23354 BITMAP* asset_select_bmp;
23355 BITMAP* asset_arrows_bmp;
23356 MIDI* asset_tunes_midi;
23357 PALETTE asset_pal;
23358
23359 8 static void load_assets()
23360 {
23361 8 asset_icons_bmp = load_asset_bmp("assets/editor/icons.bmp");
23362 8 asset_engravings_bmp = load_asset_bmp("assets/editor/engravings.bmp");
23363 8 asset_mouse_bmp = load_asset_bmp("assets/editor/mouse.bmp");
23364 8 asset_select_bmp = load_asset_bmp("assets/editor/select.bmp");
23365 8 asset_arrows_bmp = load_asset_bmp("assets/editor/arrows.bmp");
23366 8 asset_tunes_midi = load_asset_midi("assets/editor/tunes.mid");
23367 8 load_asset_pal(asset_pal, "assets/editor/pal.bmp");
23368 8 }
23369
23370 static bool application_has_loaded;
23371
23372 void dev_output_qrs(string const& fname);
23373
23374 8 int32_t main(int32_t argc,char **argv)
23375 {
23376 8 int dev_qrs_arg = used_switch(argc, argv, "-dev-qrs-zscript");
23377
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (dev_qrs_arg > 0)
23378 {
23379 if (dev_qrs_arg + 1 > argc)
23380 {
23381 printf("%d\n", argc);
23382 printf("expected -dev-qrs-zscript output.zs\n");
23383 exit(1);
23384 }
23385 string fname(argv[dev_qrs_arg + 1]);
23386 dev_output_qrs(fname);
23387 if (used_switch(argc,argv,"-q"))
23388 exit(0);
23389 }
23390
23391 8 int test_zc_arg = used_switch(argc, argv, "-test-zc");
23392
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 times.
8 if (test_zc_arg > 0)
23393 1 set_headless_mode();
23394
23395 8 zalleg_setup_allegro(App::zquest, argc, argv);
23396 8 allocate_crap();
23397
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 set_should_zprint_cb([]() {
23398 return get_qr(qr_SCRIPTERRLOG) || DEVLEVEL > 0;
23399 });
23400
23401 8 int package_arg = used_switch(argc, argv, "-package");
23402
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (package_arg > 0)
23403 {
23404 if (package_arg + 3 > argc)
23405 {
23406 printf("%d\n", argc);
23407 printf("expected -package <game.qst> <package name>\n");
23408 zq_exit(1);
23409 }
23410
23411 const char* input_filename = argv[package_arg + 1];
23412 const char* package_name = argv[package_arg + 2];
23413 if (auto error = package_create(input_filename, package_name))
23414 Z_error_fatal("%s\n", error->c_str());
23415 zq_exit(0);
23416 }
23417
23418 8 int copy_qst_arg = used_switch(argc, argv, "-copy-qst");
23419
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 5 times.
8 if (copy_qst_arg > 0)
23420 {
23421
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if (copy_qst_arg + 3 > argc)
23422 {
23423 printf("%d\n", argc);
23424 printf("expected -copy-qst <input> <output>\n");
23425 zq_exit(1);
23426 }
23427
23428 3 const char* input_filename = argv[copy_qst_arg + 1];
23429 3 const char* output_filename = argv[copy_qst_arg + 2];
23430 3 do_copy_qst_command(input_filename, output_filename);
23431 3 }
23432
23433 8 Z_title("ZQuest Classic Editor, %s", getVersionString());
23434
23435
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!get_qst_buffers())
23436 {
23437 Z_error_fatal("Error");
23438 }
23439
23440 8 undocombobuf.clear();
23441 8 undocombobuf.resize(MAXCOMBOS);
23442
23443
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if((newundotilebuf=(tiledata*)malloc(NEWMAXTILES*sizeof(tiledata)))==NULL)
23444 {
23445 Z_error_fatal("Error: no memory for tile undo buffer!");
23446 }
23447
23448 8 memset(newundotilebuf, 0, NEWMAXTILES*sizeof(tiledata));
23449
23450 8 Z_message("Resetting new tile buffer...");
23451 8 newtilebuf = (tiledata*)malloc(NEWMAXTILES*sizeof(tiledata));
23452
23453
2/2
✓ Branch 0 taken 1930500 times.
✓ Branch 1 taken 8 times.
1930508 for(int32_t j=0; j<NEWMAXTILES; j++)
23454 1930500 newtilebuf[j].data=NULL;
23455
23456 8 Z_message("OK\n");
23457
23458 8 zc_srand(time(0));
23459
23460
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7 times.
8 if (test_zc_arg > 0)
23461 {
23462 1 set_headless_mode();
23463
23464
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (test_zc_arg + 1 > argc)
23465 {
23466 printf("%d\n", argc);
23467 printf("expected -test-zc <path to test dir>\n");
23468 zq_exit(1);
23469 }
23470
23471 1 const char* test_dir = argv[test_zc_arg + 1];
23472
23473 // We need to init some stuff before loading a quest file will work.
23474 1 int fake_errno = 0;
23475 1 allegro_errno = &fake_errno;
23476 1 get_qst_buffers();
23477
23478 1 bool success = true;
23479
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (!partial_load_test(test_dir))
23480 {
23481 success = false;
23482 printf("partial_load_test failed\n");
23483 }
23484
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (success)
23485 1 printf("all tests passed\n");
23486 1 zq_exit(success ? 0 : 1);
23487 1 }
23488
23489 8 int unencrypt_qst_arg = used_switch(argc, argv, "-unencrypt-qst");
23490
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (unencrypt_qst_arg > 0)
23491 {
23492 if (unencrypt_qst_arg + 3 > argc)
23493 {
23494 printf("%d\n", argc);
23495 printf("expected -unencrypt-qst <input> <output>\n");
23496 zq_exit(1);
23497 }
23498
23499 const char* input_filename = argv[unencrypt_qst_arg + 1];
23500 const char* output_filename = argv[unencrypt_qst_arg + 2];
23501 do_unencrypt_qst_command(input_filename, output_filename);
23502 zq_exit(0);
23503 }
23504
23505 8 int uncompress_qst_arg = used_switch(argc, argv, "-uncompress-qst");
23506
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (uncompress_qst_arg > 0)
23507 {
23508 if (uncompress_qst_arg + 3 > argc)
23509 {
23510 printf("%d\n", argc);
23511 printf("expected -uncompress-qst <input> <output>\n");
23512 zq_exit(1);
23513 }
23514
23515 const char* input_filename = argv[uncompress_qst_arg + 1];
23516 const char* output_filename = argv[uncompress_qst_arg + 2];
23517 do_uncompress_qst_command(input_filename, output_filename);
23518 zq_exit(0);
23519 }
23520
23521 8 three_finger_flag=false;
23522
23523 #ifndef __EMSCRIPTEN__
23524
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if(zc_get_config("zquest","open_debug_console",0))
23525 initConsole();
23526 #endif
23527
23528 LOCK_VARIABLE(lastfps);
23529
23530 LOCK_VARIABLE(framecnt);
23531 LOCK_FUNCTION(fps_callback);
23532
23533
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(install_int_ex(fps_callback,SECS_TO_TIMER(1)))
23534 {
23535 Z_error_fatal("couldn't allocate timer");
23536 }
23537
23538
23539 LOCK_VARIABLE(dclick_status);
23540 LOCK_VARIABLE(dclick_time);
23541 8 lock_dclick_function();
23542 8 install_int(dclick_check, 20);
23543
23544 8 set_gfx_mode(GFX_TEXT,80,50,0,0);
23545
23546 8 load_assets();
23547
23548 8 Z_message("OK\n");
23549
23550
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 helpstr = util::read_text_file("docs/zquest.txt");
23551
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 zstringshelpstr = util::read_text_file("docs/zstrings.txt");
23552
23553 // loading data files...
23554
23555 8 filepath[0]=temppath[0]=0;
23556
23557 8 const char *default_path="";
23558
23559 8 strcpy(datapath,zc_get_config("zquest",data_path_name,default_path));
23560 8 strcpy(midipath,zc_get_config("zquest",midi_path_name,default_path));
23561 8 strcpy(imagepath,zc_get_config("zquest",image_path_name,default_path));
23562 8 strcpy(tmusicpath,zc_get_config("zquest",tmusic_path_name,default_path));
23563 8 chop_path(datapath);
23564 8 chop_path(midipath);
23565 8 chop_path(imagepath);
23566 8 chop_path(tmusicpath);
23567
23568 8 DisableLPalShortcuts = zc_get_config("zquest","dis_lpal_shortcut",1);
23569 8 DisableCompileConsole = zc_get_config("zquest","internal_compile_console",0);
23570 8 MouseScroll = zc_get_config("zquest","mouse_scroll",0);
23571 8 MMapCursorStyle = zc_get_config("zquest","cursorblink_style",1);
23572 8 LayerDitherBG = zc_get_config("zquest", "layer_dither_bg", -1);
23573 8 LayerDitherSz = zc_get_config("zquest", "layer_dither_sz", 3);
23574 8 InvalidBG = zc_get_config("zquest", "invalid_bg", 0);
23575 8 TileProtection = zc_get_config("zquest","tile_protection",1);
23576 8 ComboProtection = zc_get_config("zquest","combo_protection",TileProtection);
23577 8 ShowGrid = zc_get_config("zquest","show_grid",0);
23578 8 ShowCurScreenOutline = zc_get_config("zquest","show_current_screen_outline",1);
23579 8 ShowScreenGrid = zc_get_config("zquest","show_screen_grid",0);
23580 8 ShowRegionGrid = zc_get_config("zquest","show_region_grid",1);
23581 8 GridColor = zc_get_config("zquest","grid_color",15);
23582 8 CmbCursorCol = zc_get_config("zquest","combo_cursor_color",15);
23583 8 TilePgCursorCol = zc_get_config("zquest","tpage_cursor_color",15);
23584 8 CmbPgCursorCol = zc_get_config("zquest","cpage_cursor_color",15);
23585 8 TTipHLCol = zc_get_config("zquest","ttip_hl_color",13);
23586 8 CheckerCol1 = zc_get_config("zquest","checker_color_1",7);
23587 8 CheckerCol2 = zc_get_config("zquest","checker_color_2",8);
23588 8 SnapshotFormat = zc_get_config("zquest","snapshot_format",3);
23589 8 SnapshotScale = zc_get_config("zquest","snapshot_scale",2);
23590 8 SavePaths = zc_get_config("zquest","save_paths",1);
23591 8 CycleOn = zc_get_config("zquest","cycle_on",1);
23592 8 ShowFPS = zc_get_config("zquest","showfps",0)!=0;
23593 8 SaveDragResize = zc_get_config("zquest","save_drag_resize",0)!=0;
23594 8 DragAspect = zc_get_config("zquest","drag_aspect",0)!=0;
23595 8 SaveWinPos = zc_get_config("zquest","save_window_position",0)!=0;
23596 8 ComboBrush = zc_get_config("zquest","combo_brush",0);
23597 8 FloatBrush = zc_get_config("zquest","float_brush",0);
23598 8 AutoBrush = zc_get_config("zquest","autobrush",1);
23599 8 LinkedScroll = zc_get_config("zquest","linked_comboscroll",0);
23600 8 allowHideMouse = zc_get_config("ZQ_GUI","allowHideMouse",0);
23601 8 ShowFavoriteComboModes = zc_get_config("ZQ_GUI","show_fav_combo_modes",1);
23602 8 NoHighlightLayer0 = zc_get_config("zquest","no_highlight_layer0",0);
23603 8 RulesetDialog = zc_get_config("zquest","rulesetdialog",1);
23604 8 EnableTooltips = zc_get_config("zquest","enable_tooltips",1);
23605 8 TooltipsHighlight = zc_get_config("zquest","ttip_highlight",1);
23606 8 tooltip_maxtimer = vbound(zc_get_config("zquest","ttip_timer",30),0,60*60);
23607 8 ShowFFScripts = zc_get_config("zquest","showffscripts",1);
23608 8 ShowSquares = zc_get_config("zquest","showsquares",1);
23609 8 ShowFFCs = zc_get_config("zquest","showffcs",0);
23610 8 ShowInfo = zc_get_config("zquest","showinfo",1);
23611 8 skipLayerWarning = zc_get_config("zquest","skip_layer_warning",0);
23612 8 numericalFlags = zc_get_config("zquest","numerical_flags",0);
23613 8 ViewLayer2BG = zc_get_config("zquest","layer2_bg",0);
23614 8 ViewLayer3BG = zc_get_config("zquest","layer3_bg",0);
23615 8 ActiveLayerHighlight = zc_get_config("zquest","hl_active_lyr",0);
23616 8 DragCenterOfSquares = zc_get_config("zquest","drag_squares_from_center",0);
23617
23618 8 OpenLastQuest = zc_get_config("zquest","open_last_quest",0);
23619 8 ShowMisalignments = zc_get_config("zquest","show_misalignments",0);
23620 8 AnimationOn = zc_get_config("zquest","animation_on",1);
23621 8 AutoBackupRetention = zc_get_config("zquest","auto_backup_retention",2);
23622 8 AutoSaveInterval = zc_get_config("zquest","auto_save_interval",6);
23623 8 AutoSaveRetention = zc_get_config("zquest","auto_save_retention",2);
23624 8 UncompressedAutoSaves = zc_get_config("zquest","uncompressed_auto_saves",1);
23625 8 OverwriteProtection = zc_get_config("zquest","overwrite_prevention",0)!=0;
23626 8 ImportMapBias = zc_get_config("zquest","import_map_bias",0);
23627
23628 8 KeyboardRepeatDelay = zc_get_config("zquest","keyboard_repeat_delay",300);
23629 8 KeyboardRepeatRate = zc_get_config("zquest","keyboard_repeat_rate",80);
23630
23631 // Frameskip = zc_get_config("zquest","frameskip",0); //todo: this is not actually supported yet.
23632 8 RequestedFPS = zc_get_config("zquest","fps",60);
23633
23634 // Autofill for Combo Page, Tile Page
23635 8 PreFillTileEditorPage = zc_get_config("zquest","PreFillTileEditorPage",0);
23636 8 PreFillComboEditorPage = zc_get_config("zquest","PreFillComboEditorPage",0);
23637
23638 8 pixeldb = zc_get_config("ZQ_GUI","bottom_8_pixels",0);
23639 8 infobg = zc_get_config("ZQ_GUI","info_text_bg",0);
23640
23641 8 large_merged_combopane = zc_get_config("ZQ_GUI","merge_cpane_large",0);
23642 8 compact_merged_combopane = zc_get_config("ZQ_GUI","merge_cpane_compact",1);
23643
23644 8 compact_square_panels = zc_get_config("ZQ_GUI","square_panels_compact",0);
23645
23646 8 large_zoomed_fav = zc_get_config("ZQ_GUI","zoom_fav_large",0);
23647 8 compact_zoomed_fav = zc_get_config("ZQ_GUI","zoom_fav_compact",1);
23648 8 large_zoomed_cmd = zc_get_config("ZQ_GUI","zoom_cmd_large",1);
23649 8 compact_zoomed_cmd = zc_get_config("ZQ_GUI","zoom_cmd_compact",1);
23650
23651
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(zc_get_config("gui","disable_window_resizing",0))
23652 all_set_resize_flag(false);
23653
23654 8 load_hotkeys();
23655
23656 #ifdef _WIN32
23657 zqUseWin32Proc = zc_get_config("zquest","zq_win_proc_fix",0);
23658
23659 #endif
23660
23661
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (!render_timer_start())
23662 {
23663 Z_error_fatal("couldn't allocate timer");
23664 }
23665
23666 8 byte layermask = zc_get_config("zquest","layer_mask",0x7F);
23667 8 int32_t usefullscreen = zc_get_config("zquest","fullscreen",0);
23668 8 tempmode = (usefullscreen == 0 ? GFX_AUTODETECT_WINDOWED : GFX_AUTODETECT_FULLSCREEN);
23669
23670
2/2
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 8 times.
64 for(int32_t x=0; x<7; x++)
23671 {
23672 56 LayerMaskInt[x]=get_bit(&layermask,x);
23673 56 }
23674
23675 8 DuplicateAction[0] = zc_get_config("zquest","normal_duplicate_action",2);
23676 8 DuplicateAction[1] = zc_get_config("zquest","horizontal_duplicate_action",0);
23677 8 DuplicateAction[2] = zc_get_config("zquest","vertical_duplicate_action",0);
23678 8 DuplicateAction[3] = zc_get_config("zquest","both_duplicate_action",0);
23679 8 LeechUpdate = zc_get_config("zquest","leech_update",500);
23680 8 LeechUpdateTiles = zc_get_config("zquest","leech_update_tiles",1);
23681 8 OnlyCheckNewTilesForDuplicates = zc_get_config("zquest","only_check_new_tiles_for_duplicates",0);
23682 //gui_colorset = zc_get_config("zquest","gui_colorset",0);
23683
23684 8 strcpy(last_timed_save,zc_get_config("zquest","last_timed_save",""));
23685
23686 8 midi_volume = zc_get_config("zquest", "midi", 255);
23687
23688 8 abc_patternmatch = zc_get_config("zquest", "lister_pattern_matching", 1);
23689 8 NoScreenPreview = zc_get_config("zquest", "no_preview", 0);
23690
23691 8 monochrome_console = zc_get_config("CONSOLE","monochrome_debuggers",0)?1:0;
23692
23693 8 try_recovering_missing_scripts = 0;//zc_get_config("Compiler", "try_recovering_missing_scripts",0);
23694 //We need to remove all of the zeldadx refs to the config file for zquest.
23695
23696 8 set_keyboard_rate(KeyboardRepeatDelay,KeyboardRepeatRate);
23697
23698 8 is_compact = zc_get_config("ZQ_GUI","compact_mode",1);
23699 8 mapscreenbmp = nullptr;
23700 8 brushbmp = nullptr;
23701 8 brushscreen = nullptr;
23702 8 screen2 = nullptr;
23703 8 tmp_scr = nullptr;
23704 8 menu1 = nullptr;
23705 8 menu3 = nullptr;
23706
23707
2/2
✓ Branch 0 taken 10080 times.
✓ Branch 1 taken 8 times.
10088 for(int32_t i=0; i<MAXFAVORITECOMBOS; ++i)
23708 {
23709 10080 favorite_combos[i]=-1;
23710 10080 pool_combos[i].clear();
23711 10080 }
23712 8 FavoriteComboPage = 0;
23713 8 pool_dirty = true;
23714
23715
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(used_switch(argc,argv,"-d"))
23716 {
23717 set_debug(!strcmp(zquestpwd,zc_get_config("zquest","debug_this","")));
23718 }
23719
23720 8 zcmusic_init();
23721 8 zcmixer = zcmixer_create();
23722 1128 install_int_ex([](){ zcmusic_poll(); }, MSEC_TO_TIMER(25));
23723
23724 8 set_color_depth(8);
23725
23726 8 set_close_button_callback((void (*)()) hit_close_button);
23727
23728
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if(used_switch(argc,argv,"-fullscreen"))
23729 {
23730 tempmode = GFX_AUTODETECT_FULLSCREEN;
23731 }
23732
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 else if(used_switch(argc,argv,"-windowed"))
23733 {
23734 tempmode=GFX_AUTODETECT_WINDOWED;
23735 }
23736
23737 8 zq_screen_w = LARGE_W;
23738 8 zq_screen_h = LARGE_H;
23739 8 window_width = zc_get_config("zquest","window_width",-1);
23740 8 window_height = zc_get_config("zquest","window_height",-1);
23741 8 auto [w, h] = zc_get_default_display_size(LARGE_W, LARGE_H, window_width, window_height);
23742
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 int32_t videofail = is_headless() ? 0 : (set_gfx_mode(tempmode,w,h,zq_screen_w,zq_screen_h));
23743
23744 //extra block here is intentional
23745
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(videofail!=0)
23746 {
23747 quit_game();
23748 allegro_exit();
23749 }
23750
23751 8 zalleg_create_window();
23752 8 Z_message("gfx mode set at -%d %dbpp %d x %d \n",
23753 8 tempmode, get_color_depth(), zq_screen_w, zq_screen_h);
23754
23755 8 set_window_title("ZC Editor");
23756
23757 8 load_size_poses();
23758
23759
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (!is_headless())
23760 {
23761 // Just in case.
23762 while (!all_get_display()) {
23763 al_rest(1);
23764 }
23765
23766 al_resize_display(all_get_display(), w, h);
23767 }
23768
23769
23770 #ifndef __EMSCRIPTEN__
23771
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
8 if (!all_get_fullscreen_flag() && !is_headless()) {
23772 al_resize_display(all_get_display(), w, h);
23773
23774 int window_w = al_get_display_width(all_get_display());
23775 int window_h = al_get_display_height(all_get_display());
23776
23777 int new_x = zc_get_config("zquest","window_x",0);
23778 int new_y = zc_get_config("zquest","window_y",0);
23779 if(zc_get_config("zquest","save_window_position",0) && (new_x || new_y))
23780 {
23781 //load saved position
23782 //already stored in new_x/new_y
23783 }
23784 else
23785 {
23786 //Get default position
23787 ALLEGRO_MONITOR_INFO info;
23788 al_get_monitor_info(0, &info);
23789
23790 int mw = (info.x2 - info.x1);
23791 int mh = (info.y2 - info.y1);
23792 new_x = mw / 2 - window_w / 2;
23793 new_y = mh / 2 - window_h / 2;
23794 //Don't spawn the window too far down (taskbar?)
23795 if(new_y + window_h > mh - 72)
23796 new_y = mh-72-window_h;
23797 }
23798 #ifdef ALLEGRO_MACOSX
23799 if (zc_get_config("zquest","save_window_position",0))
23800 al_set_window_position(all_get_display(), new_x, new_y);
23801 #else
23802 al_set_window_position(all_get_display(), new_x, new_y);
23803 #endif
23804 }
23805 #endif
23806
23807 8 position_mouse(zq_screen_w/2,zq_screen_h/2);
23808
23809 8 dmapbmp_small = create_bitmap_ex(8,65,33);
23810 8 dmapbmp_large = create_bitmap_ex(8,177,81);
23811
23812
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!screen2 || !tmp_scr || !menu1 || !menu3 || !dmapbmp_large || !dmapbmp_large || !brushbmp || !brushscreen)// || !brushshadowbmp )
23813 {
23814 Z_error_fatal("Failed to create system bitmaps!\n");
23815 return 1;
23816 }
23817
23818 8 int quick_assign_arg = used_switch(argc, argv, "-quick-assign");
23819
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6 times.
8 if (quick_assign_arg > 0)
23820 {
23821 6 is_zq_replay_test = true;
23822 6 set_headless_mode();
23823
23824 6 int load_ret = load_quest(argv[quick_assign_arg + 1], false);
23825 6 bool success = load_ret == qe_OK;
23826
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (!success)
23827 {
23828 printf("Failed to load quest: %d\n", load_ret);
23829 zq_exit(1);
23830 }
23831
23832 6 success = do_compile_and_slots(1, false);
23833
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (!success)
23834 {
23835 printf("Failed to compile\n");
23836 zq_exit(1);
23837 }
23838
23839 6 success = save_quest(argv[quick_assign_arg + 1], false) == 0;
23840
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (!success)
23841 {
23842 printf("Failed to save quest\n");
23843 zq_exit(1);
23844 }
23845
23846 6 zq_exit(0);
23847 6 }
23848
23849 8 int smart_assign_arg = used_switch(argc, argv, "-smart-assign");
23850
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (smart_assign_arg > 0)
23851 {
23852 is_zq_replay_test = true;
23853 set_headless_mode();
23854
23855 int load_ret = load_quest(argv[smart_assign_arg + 1], false);
23856 bool success = load_ret == qe_OK;
23857 if (!success)
23858 {
23859 printf("Failed to load quest: %d\n", load_ret);
23860 zq_exit(1);
23861 }
23862
23863 success = do_compile_and_slots(2, false);
23864 if (!success)
23865 {
23866 printf("Failed to compile\n");
23867 zq_exit(1);
23868 }
23869
23870 success = save_quest(argv[smart_assign_arg + 1], false) == 0;
23871 if (!success)
23872 {
23873 printf("Failed to save quest\n");
23874 zq_exit(1);
23875 }
23876
23877 zq_exit(0);
23878 }
23879
23880 8 int export_strings_arg = used_switch(argc, argv, "-export-strings");
23881
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 times.
8 if (export_strings_arg > 0)
23882 {
23883
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (export_strings_arg + 3 > argc)
23884 {
23885 printf("%d\n", argc);
23886 printf("expected -export-strings input.qst output.tsv\n");
23887 zq_exit(1);
23888 }
23889
23890 1 is_zq_replay_test = true;
23891 1 set_headless_mode();
23892
23893 1 int load_ret = load_quest(argv[export_strings_arg + 1], false);
23894 1 bool success = load_ret == qe_OK;
23895
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (!success)
23896 {
23897 printf("Failed to load quest: %d\n", load_ret);
23898 zq_exit(1);
23899 }
23900
23901 1 success = save_strings_tsv(argv[export_strings_arg + 2]);
23902
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (!success)
23903 {
23904 printf("Failed to export strings\n");
23905 zq_exit(1);
23906 }
23907
23908 1 zq_exit(0);
23909 1 }
23910
23911
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (!is_headless())
23912 {
23913 zc_set_palette(asset_pal);
23914 get_palette(RAMpal);
23915 load_colorset(gui_colorset);
23916 zc_set_palette(RAMpal);
23917 clear_to_color(screen,vc(0));
23918 }
23919
23920 8 zScript = string();
23921 8 strcpy(zScriptBytes, "0 Bytes in Buffer");
23922
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 8 times.
20 for(int32_t i=0; i<MOUSE_BMP_MAX; i++)
23923 {
23924
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t j=0; j<4; j++)
23925 {
23926 48 mouse_bmp[i][j] = NULL;
23927 48 mouse_bmp_1x[i][j] = NULL;
23928 48 }
23929 12 }
23930 8 load_mice();
23931 8 gui_mouse_focus=0;
23932 8 MouseSprite::set(ZQM_NORMAL);
23933 8 render_zq(); // Ensure the rendering bitmaps are setup.
23934
23935 #ifdef __EMSCRIPTEN__
23936 em_mark_ready_status();
23937 #endif
23938
23939 8 load_icons();
23940
23941 8 bool load_last_timed_save=false;
23942
23943 8 load_recent_quests();
23944 8 refresh_recent_menu();
23945 //clearConsole();
23946
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
8 if((last_timed_save[0]!=0)&&(exists(last_timed_save)))
23947 {
23948 if(jwin_alert("ZQuest","It appears that ZQuest crashed last time.","Would you like to load the last timed save?",NULL,"&Yes","&No",'y','n',get_zc_font(font_lfont))==1)
23949 {
23950 int32_t ret = load_quest(last_timed_save);
23951
23952 if(ret == qe_OK)
23953 {
23954 strcpy(filepath,last_timed_save);
23955 load_last_timed_save=true;
23956 saved=false;
23957 }
23958 else
23959 {
23960 jwin_alert("Error","Unable to reload the last timed save.",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
23961 }
23962 }
23963 }
23964
23965
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 times.
8 if(!load_last_timed_save)
23966 {
23967 1 strcpy(filepath,zc_get_config("zquest",last_quest_name,""));
23968
23969
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if(argc>1 && argv[1][0]!='-')
23970 {
23971 int32_t ret = load_quest(argv[1]);
23972
23973 if(ret == qe_OK)
23974 {
23975 first_save=true;
23976 strcpy(filepath,argv[1]);
23977 refresh(rALL);
23978 }
23979 }
23980
2/8
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
1 else if(OpenLastQuest&&filepath[0]&&exists(filepath)&&!used_switch(argc,argv,"-new"))
23981 {
23982 int32_t ret = load_quest(filepath);
23983
23984 if(ret == qe_OK)
23985 {
23986 first_save=true;
23987 refresh(rALL);
23988 }
23989 else
23990 {
23991 filepath[0]=temppath[0]=0;
23992 first_save=false;
23993 }
23994 }
23995 else
23996 {
23997
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (onNew() == D_CLOSE)
23998 {
23999 1 Z_message("User canceled creating new quest, closing.\n");
24000 1 exit(0);
24001 }
24002
24003 //otherwise the blank quest gets the name of the last loaded quest... not good! -DD
24004 filepath[0]=temppath[0]=0;
24005 first_save=false;
24006 }
24007 }
24008
24009
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if(used_switch(argc,argv,"-q"))
24010 {
24011 Z_message("-q switch used, quitting program.\n");
24012 zq_exit(0);
24013 }
24014
24015
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 for(int32_t x=0; x<MAXITEMS; x++)
24016 {
24017 lens_hint_item[x][0]=0;
24018 lens_hint_item[x][1]=0;
24019 }
24020
24021
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 for(int32_t x=0; x<MAXWPNS; x++)
24022 {
24023 lens_hint_weapon[x][0]=0;
24024 lens_hint_weapon[x][1]=0;
24025 }
24026
24027 7 load_selections();
24028 7 load_arrows();
24029 7 clear_to_color(menu1,vc(0));
24030 7 DIALOG_PLAYER *player2=init_dialog(dialogs,-1);
24031
24032 7 get_palette(RAMpal);
24033
24034 7 rgb_map = &zq_rgb_table;
24035
24036 #ifdef __EMSCRIPTEN__
24037 {
24038 int qs_map = EM_ASM_INT({
24039 return new URL(location.href).searchParams.get('map') ?? -1;
24040 });
24041 int qs_screen = EM_ASM_INT({
24042 return new URL(location.href).searchParams.get('screen') ?? -1;
24043 });
24044 if (qs_map != -1 && qs_screen != -1) {
24045 Map.setCurrMap(qs_map);
24046 Map.setCurrScr(qs_screen);
24047 }
24048 }
24049 #endif
24050
24051 // setup_combo_animations();
24052 7 pause_refresh = false;
24053 7 refresh_pal();
24054 7 refresh(rALL);
24055
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 for(int q = 0; q < brush_width_menu.size(); ++q)
24056 brush_width_menu.at(q)->select(q==0);
24057
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 for(int q = 0; q < brush_height_menu.size(); ++q)
24058 brush_height_menu.at(q)->select(q==0);
24059 7 set_filltype(1);
24060
24061 7 rebuild_trans_table();
24062
24063
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if (!is_headless())
24064 {
24065 set_display_switch_mode(SWITCH_BACKGROUND);
24066 set_display_switch_callback(SWITCH_OUT, switch_out);
24067 set_display_switch_callback(SWITCH_IN, switch_in);
24068 }
24069
24070
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if(!update_dialog(player2))
24071 exiting_program = true;
24072 //clear_keybuf();
24073 7 media_menu.disable_uid(MENUID_MEDIA_CHANGETRACK, true);
24074 7 disable_hotkey(ZQKEY_CHANGE_TRACK, true);
24075
24076 7 fix_drawing_mode_menu();
24077
24078
24079 #ifdef _WIN32
24080
24081 if(zqUseWin32Proc != FALSE)
24082 {
24083 al_trace("Config file warning: \"zq_win_proc_fix\" enabled switch found. This can cause crashes on some computers.\n");
24084 win32data.zqSetDefaultThreadPriority(0);
24085 win32data.zqSetCustomCallbackProc(al_get_win_window_handle(all_get_display()));
24086 }
24087
24088 #endif
24089
24090 7 time(&auto_save_time_start);
24091
24092 7 FFCore.init();
24093 7 ZQincludePaths = FFCore.includePaths;
24094
24095 7 Map.setCopyFFC(-1); //Do not have an initial ffc on the clipboard.
24096 7 brush_menu.select_uid(MENUID_BRUSH_AUTOBRUSH, AutoBrush);
24097 7 brush_menu.disable_uid(MENUID_BRUSH_WIDTH, AutoBrush);
24098 7 brush_menu.disable_uid(MENUID_BRUSH_HEIGHT, AutoBrush);
24099 7 brush_menu.select_uid(MENUID_BRUSH_COMBOBRUSH, ComboBrush);
24100 7 brush_menu.select_uid(MENUID_BRUSH_FLOATBRUSH, FloatBrush);
24101
24102 7 call_foo_dlg();
24103
24104 7 application_has_loaded = true;
24105
24106
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 while(!exiting_program)
24107 {
24108 handle_sentry_tags();
24109
24110 #ifdef _WIN32
24111 if(zqUseWin32Proc != FALSE)
24112 win32data.Update(Frameskip); //experimental win32 fixes
24113 #endif
24114 check_autosave();
24115 ++alignment_arrow_timer;
24116
24117 if(alignment_arrow_timer>63)
24118 {
24119 alignment_arrow_timer=0;
24120 }
24121 ++frame;
24122
24123 file_menu.disable_uid(MENUID_FILE_SAVE, saved||disable_saving||OverwriteProtection);
24124 file_menu.disable_uid(MENUID_FILE_REVERT, saved||disable_saving||OverwriteProtection);
24125 file_menu.disable_uid(MENUID_FILE_SAVEAS, disable_saving);
24126
24127 fixtools_menu.disable_uid(MENUID_FIXTOOL_OLDSTRING,
24128 !(get_qr(qr_OLD_STRING_EDITOR_MARGINS)
24129 ||get_qr(qr_STRING_FRAME_OLD_WIDTH_HEIGHT)));
24130
24131 edit_menu.disable_uid(MENUID_EDIT_UNDO, !Map.CanUndo());
24132 edit_menu.disable_uid(MENUID_EDIT_REDO, !Map.CanRedo());
24133
24134 bool canpaste = Map.CanPaste();
24135 edit_menu.disable_uid(MENUID_EDIT_PASTE, !canpaste);
24136 edit_menu.disable_uid(MENUID_EDIT_PASTEALL, !canpaste);
24137 edit_menu.disable_uid(MENUID_EDIT_ADVPASTE, !canpaste);
24138 edit_menu.disable_uid(MENUID_EDIT_SPECPASTE, !canpaste);
24139 rc_menu_screen.disable_uid(MENUID_RCSCREEN_PASTE, !canpaste);
24140 rc_menu_screen.disable_uid(MENUID_RCSCREEN_ADVPASTE, !canpaste);
24141 rc_menu_screen.disable_uid(MENUID_RCSCREEN_SPECPASTE, !canpaste);
24142 for(MenuItem& mit : paste_menu.inner())
24143 mit.disable(!canpaste);
24144 for(MenuItem& mit : paste_item_menu.inner())
24145 mit.disable(!canpaste);
24146
24147 edit_menu.disable_uid(MENUID_EDIT_COPY, !(Map.CurrScr()->valid&mVALID));
24148 edit_menu.disable_uid(MENUID_EDIT_DELETE, !(Map.CurrScr()->valid&mVALID));
24149
24150 // Are some things selected?
24151 view_menu.select_uid(MENUID_VIEW_WALKABILITY, Flags&cWALK);
24152 view_menu.select_uid(MENUID_VIEW_FLAGS, Flags&cFLAGS);
24153 view_menu.select_uid(MENUID_VIEW_CSET, Flags&cCSET);
24154 view_menu.select_uid(MENUID_VIEW_TYPES, Flags&cCTYPE);
24155 view_menu.select_uid(MENUID_VIEW_INFO, ShowInfo);
24156 view_menu.select_uid(MENUID_VIEW_SQUARES, ShowSquares);
24157 view_menu.select_uid(MENUID_VIEW_FFCS, ShowFFCs);
24158 view_menu.select_uid(MENUID_VIEW_SCRIPTNAMES, ShowFFScripts);
24159 view_menu.select_uid(MENUID_VIEW_GRID, ShowGrid);
24160 view_menu.select_uid(MENUID_VIEW_SCREENGRID, ShowScreenGrid);
24161 view_menu.select_uid(MENUID_VIEW_REGIONGRID, ShowRegionGrid);
24162 view_menu.select_uid(MENUID_VIEW_CURSCROUTLINE, ShowCurScreenOutline);
24163 view_menu.select_uid(MENUID_VIEW_DARKNESS, get_qr(qr_NEW_DARKROOM) && (Flags&cNEWDARK));
24164 view_menu.select_uid(MENUID_VIEW_L2BG, ViewLayer2BG);
24165 view_menu.select_uid(MENUID_VIEW_L3BG, ViewLayer3BG);
24166 view_menu.select_uid(MENUID_VIEW_LAYERHIGHLIGHT, ActiveLayerHighlight);
24167
24168 maps_menu.disable_uid(MENUID_MAPS_NEXT, !map_count || Map.getCurrMap() >= map_count);
24169 maps_menu.disable_uid(MENUID_MAPS_PREV, Map.getCurrMap()<=0);
24170
24171 etc_menu.disable_uid(MENUID_ETC_VIDMODE, isFullScreen()==1);
24172 etc_menu.select_uid(MENUID_ETC_FULLSCREEN, isFullScreen()==1);
24173
24174 if(!update_dialog(player2))
24175 exiting_program = true;
24176
24177 //clear_keybuf();
24178 handle_close_btn_quit();
24179 }
24180
24181 7 zq_exit(0);
24182 7 return 0;
24183 }
24184 END_OF_MAIN()
24185
24186 11 void zq_exit(int code)
24187 {
24188 11 set_is_exiting();
24189 11 parser_console.kill();
24190 11 killConsole();
24191
24192 11 quit_game();
24193 11 allegro_exit();
24194 11 exit(code);
24195 }
24196
24197 56 void init_bitmap(BITMAP** bmp, int32_t w, int32_t h)
24198 {
24199
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
56 if(*bmp)
24200 destroy_bitmap(*bmp);
24201 56 *bmp = create_bitmap_ex(8,w,h);
24202 56 clear_bitmap(*bmp);
24203 56 }
24204 8 void load_size_poses()
24205 {
24206 8 ttip_uninstall_all();
24207
24208 8 FONT* favcmdfont = get_custom_font(CFONT_FAVCMD);
24209 8 FONT* guifont = get_custom_font(CFONT_GUI);
24210
24211 8 d_nbmenu_proc(MSG_START, &dialogs[0], 0);
24212
24213 8 commands_list.xscale = command_buttonwidth;
24214 8 commands_list.yscale = 10+text_height(favcmdfont);
24215
24216 8 auto drawmode_wid = 64;
24217
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 8 times.
56 for(auto q = 0; q < dm_max; ++q)
24218 {
24219 48 auto wid = text_length(guifont, dm_names[q]);
24220
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(wid > drawmode_wid)
24221 drawmode_wid = wid;
24222 48 }
24223
24224 //Main GUI objects
24225
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(is_compact)
24226 {
24227 8 num_combo_cols = 2;
24228 8 combo_col_scale = 16;
24229
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if(compact_merged_combopane)
24230 {
24231 8 num_combo_cols = 1;
24232 8 combo_col_scale = 32;
24233 8 }
24234
24235 8 mapscreen_x=0;
24236 8 mapscreen_y=dialogs[0].h;
24237 8 mapscreen_screenunit_scale=3;
24238 8 mapscreen_single_scale = (double)mapscreen_screenunit_scale / Map.getViewSize();
24239 8 showedges=0;
24240 8 showallpanels=0;
24241
24242 8 blackout_color=8;
24243
24244 8 auto mapscr_wid = (((showedges?2:0)+16)*16*mapscreen_screenunit_scale);
24245 8 combolist_window.w=zq_screen_w-mapscr_wid;
24246 8 combolist_window.x=zq_screen_w-combolist_window.w;
24247
24248 8 favorites_window.x=combolist_window.x;
24249 8 favorites_window.w=combolist_window.w;
24250 8 favorites_window.h=136;
24251 8 favorites_window.y=zq_screen_h-favorites_window.h;
24252
24253 8 combolist_window.y=0;
24254 8 combolist_window.h=favorites_window.y-combolist_window.y;
24255
24256 8 combo_preview.x=zq_screen_w-32-8;
24257 8 combo_preview.y=combolist_window.y+6;
24258 8 combo_preview.w=32;
24259 8 combo_preview.h=32;
24260 8 combo_preview2.clear();
24261
24262 8 auto col_wid = 4*combo_col_scale;
24263 8 auto cols_wid = col_wid * num_combo_cols;
24264 8 auto cols_spacing = (combolist_window.w-cols_wid)/(num_combo_cols+1);
24265
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
16 for(auto q = 0; q < num_combo_cols; ++q)
24266 {
24267 8 combolist[q].x=combolist_window.x+(cols_spacing*(q+1))+(col_wid*q);
24268 8 combolist[q].y=combolist_window.y+54;
24269 8 combolist[q].w=4;
24270 8 combolist[q].h=compact_merged_combopane ? 15 : 30;
24271 8 combolist[q].xscale = combo_col_scale;
24272 8 combolist[q].yscale = combo_col_scale;
24273
24274 8 comboaliaslist[q].x = combolist[q].x;
24275 8 comboaliaslist[q].y = combolist[q].y;
24276 8 comboaliaslist[q].w = 4;
24277 8 comboaliaslist[q].h = compact_merged_combopane ? 13 : 26;
24278 8 comboaliaslist[q].xscale = combo_col_scale;
24279 8 comboaliaslist[q].yscale = combo_col_scale;
24280
24281 8 combolistscrollers[q].w=2;
24282 8 combolistscrollers[q].h=1;
24283 8 combolistscrollers[q].xscale=11;
24284 8 combolistscrollers[q].yscale=11;
24285 8 combolistscrollers[q].x=combolist[q].x+(combolist[q].w*combolist[q].xscale/2)-11;
24286 8 combolistscrollers[q].y=combolist[q].y-combolistscrollers[q].th()-3;
24287 8 }
24288
24289 8 comboalias_preview.x=zq_screen_w-((combolist_window.w+64)/2);
24290 8 comboalias_preview.h=64;
24291 8 comboalias_preview.y=favorites_window.y-comboalias_preview.h-8;
24292 8 comboalias_preview.w=64;
24293
24294 8 combo_merge_btn.w = 20;
24295 8 combo_merge_btn.h = 20;
24296 8 combo_merge_btn.x = zq_screen_w-(combolist_window.w+combo_merge_btn.w)/2;
24297 8 combo_merge_btn.y = combolist[0].y-combo_merge_btn.h;
24298
24299
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if(num_combo_cols == 1)
24300 {
24301 8 combolistscrollers[0].x += 34;
24302 8 }
24303 8 drawmode_btn.x = combolist_window.x-drawmode_wid;
24304 8 drawmode_btn.y = 0;
24305 8 drawmode_btn.w = drawmode_wid;
24306 8 drawmode_btn.h = mapscreen_y;
24307
24308 8 compactbtn.w = text_length(guifont,"> Compact")+10;
24309 8 compactbtn.x = drawmode_btn.x-compactbtn.w;
24310 8 compactbtn.y = drawmode_btn.y;
24311 8 compactbtn.h = drawmode_btn.h;
24312
24313 8 zoominbtn.w = text_length(guifont,"+")+10;
24314 8 zoominbtn.x = compactbtn.x-zoominbtn.w;
24315 8 zoominbtn.y = compactbtn.y;
24316 8 zoominbtn.h = compactbtn.h;
24317
24318 8 zoomoutbtn.w = text_length(guifont,"-")+10;
24319 8 zoomoutbtn.x = zoominbtn.x-zoomoutbtn.w;
24320 8 zoomoutbtn.y = compactbtn.y;
24321 8 zoomoutbtn.h = compactbtn.h;
24322
24323
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 8 times.
80 for(int32_t i=0; i<=8; i++)
24324 {
24325 72 map_page_bar[i].w = 48;
24326 72 map_page_bar[i].x = mapscreen_x+(i*48);
24327 72 map_page_bar[i].y = mapscreen_y+(11*16*mapscreen_screenunit_scale);
24328 72 map_page_bar[i].h = text_height(guifont)+12;
24329 72 }
24330
24331 8 minimap.w=7+48*3;
24332 8 minimap.h=16+27*3;
24333
24334 8 layer_panel.x=map_page_bar[6].x;
24335 8 layer_panel.y=map_page_bar[0].y;
24336 8 layer_panel.w=combolist_window.x - layer_panel.x;
24337 8 layer_panel.h=map_page_bar[0].h;
24338 8 layerpanel_buttonwidth = 51;
24339 8 layerpanel_buttonheight = layer_panel.h;
24340 8 layerpanel_checkbox_hei = layerpanel_buttonheight-4;
24341 8 layerpanel_checkbox_wid = 15;
24342
24343 8 minimap.x=3;
24344 8 minimap.y=layer_panel.y+layer_panel.h+4;
24345
24346 8 real_minimap.x = minimap.x+3;
24347 8 real_minimap.y = minimap.y+5;
24348 8 real_minimap.w = 16;
24349 8 real_minimap.h = 9;
24350 8 real_minimap.xscale = 9;
24351 8 real_minimap.yscale = 9;
24352 8 real_minimap.fw = real_minimap.xscale*8;
24353 8 real_minimap.fh = real_minimap.yscale*8;
24354
24355 8 int upscale_mm = 3;
24356 8 int xwid = real_minimap.tw()*(upscale_mm-1);
24357 8 int xhei = real_minimap.th()*(upscale_mm-1);
24358 8 minimap_zoomed.set(minimap.x, minimap.y-xhei, minimap.w+xwid, minimap.h+xhei+4);
24359 8 real_minimap_zoomed.set(minimap_zoomed.x+3, minimap_zoomed.y+5, real_minimap.w, real_minimap.h, real_minimap.xscale*upscale_mm, real_minimap.yscale*upscale_mm);
24360 8 real_minimap_zoomed.fw = real_minimap_zoomed.xscale*8;
24361 8 real_minimap_zoomed.fh = real_minimap_zoomed.yscale*8;
24362
24363 8 screrrorpos.x = combolist_window.x - 3;
24364 8 screrrorpos.y = layer_panel.y - 16;
24365
24366 8 mouse_scroll_h=10;
24367
24368 8 favorites_list.x=favorites_window.x+8;
24369 8 favorites_list.y=favorites_window.y+16;
24370 8 favorites_list.xscale = 16;
24371 8 favorites_list.yscale = 16;
24372 8 favorites_list.w=(favorites_window.w-16)/favorites_list.xscale;
24373 8 favorites_list.h=(favorites_window.h-24)/favorites_list.yscale;
24374
24375 8 commands_list.w=4;
24376
24377 8 int bh = commands_list.yscale;
24378 8 int bw = 26;
24379 8 commands_window.w=commands_list.w*commands_list.xscale+10+bw;
24380 8 commands_window.x=combolist_window.x-commands_window.w;
24381 8 commands_window.y=layer_panel.y+layer_panel.h;
24382 8 commands_window.h=zq_screen_h-commands_window.y;
24383 8 int bx = commands_window.x+2;
24384
24385 8 commands_list.y=commands_window.y+4;
24386 8 commands_list.h=(zq_screen_h - commands_list.y) / commands_list.yscale;
24387 8 commands_list.x=bx+bw;
24388
24389 8 commands_zoombtn.w = bw;
24390 8 commands_zoombtn.h = bh;
24391 8 commands_zoombtn.x = bx;
24392 8 commands_zoombtn.y = commands_list.y;
24393
24394 8 commands_infobtn.w = bw;
24395 8 commands_infobtn.h = bh;
24396 8 commands_infobtn.x = bx;
24397 8 commands_infobtn.y = commands_zoombtn.y + commands_infobtn.h;
24398
24399 8 commands_x.w = bw;
24400 8 commands_x.h = bh;
24401 8 commands_x.x = bx;
24402 8 commands_x.y = commands_infobtn.y + commands_x.h;
24403
24404 8 commands_txt.clear();
24405
24406 8 main_panel.x = 0;
24407 8 main_panel.y = layer_panel.y+layer_panel.h;
24408 8 main_panel.w = commands_window.x - main_panel.x;
24409 8 main_panel.h = 76+32;
24410 8 preview_panel = main_panel;
24411 8 preview_panel.x = 0;
24412 8 preview_panel.w = commands_window.x - preview_panel.x;
24413
24414 8 preview_text.x = preview_panel.x+3;
24415 8 preview_text.y = preview_panel.y+3;
24416 8 preview_text.w = 2;
24417 8 preview_text.h = 6;
24418 8 preview_text.xscale = 10;
24419 8 preview_text.yscale = text_height(get_zc_font(font_lfont_l));
24420
24421 8 panel_align = 1;
24422 8 int swapbtnw = 32, swapbtnh = 20;
24423 8 int swapbtnx = main_panel.x+main_panel.tw()-swapbtnw;
24424 8 squarepanel_swap_btn.set(swapbtnx, zq_screen_h-swapbtnh, swapbtnw, swapbtnh);
24425
24426 8 int sqx = minimap.x+minimap.tw();
24427 8 squares_panel.set(sqx,main_panel.y,main_panel.tw()-sqx,main_panel.th());
24428
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if(compact_square_panels)
24429 {
24430 int cmpy = main_panel.y+(main_panel.th()/2);
24431 squarepanel_up_btn.set(swapbtnx, cmpy-swapbtnh, swapbtnw, swapbtnh);
24432 squarepanel_down_btn.set(swapbtnx, cmpy, swapbtnw, swapbtnh);
24433
24434 txtoffs_single.x = 18;
24435 txtoffs_single.y = 36;
24436 txtoffs_double_1.x = 18;
24437 txtoffs_double_1.y = 36;
24438 txtoffs_double_2.x = 18;
24439 txtoffs_double_2.y = 36 + text_height(get_custom_font(CFONT_GUI));
24440
24441 //Clear them all- if they stay cleared, they are invisible.
24442 itemsqr_pos.clear();
24443 stairsqr_pos.clear();
24444 warparrival_pos.clear();
24445 flagsqr_pos.clear();
24446 enemy_prev_pos.clear();
24447 for(int q = 0; q < 4; ++q)
24448 warpret_pos[q].clear();
24449
24450 int sqr_x1 = sqx+12;
24451 int sqr_y1 = main_panel.y+12;
24452 int sqr_xoffs = (16*2)+4 + 12;
24453 switch(compact_active_panel)
24454 {
24455 case 0: //Warp Squares
24456 {
24457 int x = sqr_x1;
24458 for(int q = 0; q < 4; ++q)
24459 {
24460 warpret_pos[q].set(x,sqr_y1,(16*2)+4,(16*2)+4);
24461 x += sqr_xoffs;
24462 }
24463 break;
24464 }
24465 case 1: //Other Squares
24466 {
24467 itemsqr_pos.set(sqr_x1+(sqr_xoffs*0), sqr_y1, (16*2)+4,(16*2)+4);
24468 stairsqr_pos.set(sqr_x1+(sqr_xoffs*1), sqr_y1, (16*2)+4,(16*2)+4);
24469 warparrival_pos.set(sqr_x1+(sqr_xoffs*2), sqr_y1, (16*2)+4,(16*2)+4);
24470 flagsqr_pos.set(sqr_x1+(sqr_xoffs*3), sqr_y1, (16*2)+4,(16*2)+4);
24471 break;
24472 }
24473 case 2: //Enemy Preview
24474 {
24475 enemy_prev_pos.set(sqr_x1, sqr_y1, 5, 2, 32, 32);
24476 break;
24477 }
24478 }
24479 }
24480 else
24481 {
24482 8 squarepanel_up_btn.clear();
24483 8 squarepanel_down_btn.clear();
24484 8 txtoffs_single.x = 10;
24485 8 txtoffs_single.y = 22;
24486 8 txtoffs_double_1.x = 10;
24487 8 txtoffs_double_1.y = 22;
24488 8 txtoffs_double_2.x = 10;
24489 8 txtoffs_double_2.y = 30;
24490
24491
24492 8 int sqr_x1 = sqx+24;
24493 8 int sqr_y1 = main_panel.y+12;
24494 8 int sqr_y2 = sqr_y1+42;
24495 8 int sqr_xdist = 32;
24496 8 itemsqr_pos.set(sqr_x1+(sqr_xdist*0),sqr_y1,20,20);
24497 8 stairsqr_pos.set(sqr_x1+(sqr_xdist*1),sqr_y1,20,20);
24498 8 warparrival_pos.set(sqr_x1+(sqr_xdist*2),sqr_y1,20,20);
24499 8 flagsqr_pos.set(sqr_x1+(sqr_xdist*3),sqr_y1,20,20);
24500
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 8 times.
40 for(auto q = 0; q < 4; ++q)
24501 {
24502 32 warpret_pos[q].set(sqr_x1+(sqr_xdist*q),sqr_y2,20,20);
24503 32 }
24504 8 enemy_prev_pos.set(sqr_x1+(sqr_xdist*4), sqr_y1, 4, 3, 16, 16);
24505 8 enemy_prev_pos.fw = enemy_prev_pos.xscale*2;
24506 8 enemy_prev_pos.fh = enemy_prev_pos.yscale*2;
24507 }
24508
24509 8 auto& last_alias_list = comboaliaslist[num_combo_cols-1];
24510 8 combopool_preview.x=comboaliaslist[0].x;
24511 8 combopool_preview.y=last_alias_list.y+(last_alias_list.h*last_alias_list.yscale)+16;
24512 8 combopool_preview.w=(last_alias_list.x+(last_alias_list.w*last_alias_list.xscale))-comboaliaslist[0].x;
24513 8 combopool_preview.h=zq_screen_h-8-combopool_preview.y;
24514 8 combopool_preview.w -= combopool_preview.w%16;
24515 8 combopool_preview.h -= combopool_preview.h%16;
24516
24517 8 FONT* tfont = get_zc_font(font_lfont_l);
24518 8 combopool_prevbtn.w = text_length(tfont, "Unweighted")+10;
24519 8 combopool_prevbtn.h = 11;
24520 8 combopool_prevbtn.x = combopool_preview.x;
24521 8 combopool_prevbtn.y = combopool_preview.y-combopool_prevbtn.h;
24522
24523 8 mappage_count = 6;
24524
24525 8 txfont = get_zc_font(font_lfont_l);
24526 8 combo_preview_text1.set(combo_preview.x-5,combo_preview.y,1,3,1,text_height(txfont));
24527 8 combo_preview_text2.clear();
24528
24529 8 favorites_x.w = 17;
24530 8 favorites_infobtn.w = 17;
24531 8 favorites_zoombtn.w = 17;
24532 8 favorites_pgleft.w = 17;
24533 8 favorites_pgright.w = 17;
24534 8 }
24535 else
24536 {
24537 num_combo_cols = 4;
24538 combo_col_scale = 16;
24539 if(large_merged_combopane)
24540 {
24541 num_combo_cols = 2;
24542 combo_col_scale = 32;
24543 }
24544
24545 mapscreen_x=0;
24546 mapscreen_y=dialogs[0].h;
24547 mapscreen_screenunit_scale=2;
24548 mapscreen_single_scale = (double)mapscreen_screenunit_scale / Map.getViewSize();
24549 showedges=Map.getViewSize() <= 2 ? 1 : 0;
24550 showallpanels=0;
24551
24552 blackout_color=8;
24553
24554 favorites_window.h=136;
24555 favorites_window.y=zq_screen_h-favorites_window.h;
24556
24557 auto mapscr_wid = (((2)+16)*16*mapscreen_screenunit_scale);
24558 combolist_window.w=zq_screen_w-mapscr_wid;
24559 combolist_window.x=zq_screen_w-combolist_window.w;
24560 combolist_window.y=0;
24561 combolist_window.h=favorites_window.y-combolist_window.y;
24562
24563 favorites_window.x=combolist_window.x;
24564 favorites_window.w=combolist_window.w;
24565
24566 combo_preview.x=(zq_screen_w-(combolist_window.w/2))-40;
24567 combo_preview.y=combolist_window.y+6;
24568 combo_preview.w=32;
24569 combo_preview.h=32;
24570 combo_preview2 = combo_preview;
24571 combo_preview2.x += 48;
24572
24573 auto col_wid = 4*combo_col_scale;
24574 auto cols_wid = col_wid * num_combo_cols;
24575 auto cols_spacing = (combolist_window.w-cols_wid)/(num_combo_cols+1);
24576 for(auto q = 0; q < num_combo_cols; ++q)
24577 {
24578 combolist[q].x=combolist_window.x+(cols_spacing*(q+1))+(col_wid*q);
24579 combolist[q].y=combolist_window.y+60;
24580 combolist[q].w=4;
24581 combolist[q].h=large_merged_combopane ? 15 : 30;
24582 combolist[q].xscale = combo_col_scale;
24583 combolist[q].yscale = combo_col_scale;
24584
24585 comboaliaslist[q].x=combolist[q].x;
24586 comboaliaslist[q].y=combolist[q].y;
24587 comboaliaslist[q].w=4;
24588 comboaliaslist[q].h=large_merged_combopane ? 12 : 25;
24589 comboaliaslist[q].xscale = combo_col_scale;
24590 comboaliaslist[q].yscale = combo_col_scale;
24591
24592 combolistscrollers[q].w=2;
24593 combolistscrollers[q].h=1;
24594 combolistscrollers[q].xscale=11;
24595 combolistscrollers[q].yscale=11;
24596 combolistscrollers[q].x=combolist[q].x+(combolist[q].w*combolist[q].xscale/2)-11;
24597 combolistscrollers[q].y=combolist[q].y-combolistscrollers[q].th()-2;
24598 }
24599
24600 comboalias_preview.x=zq_screen_w-((combolist_window.w+64)/2);
24601 comboalias_preview.h=64;
24602 comboalias_preview.w=64;
24603 comboalias_preview.y=favorites_window.y-comboalias_preview.h-8;
24604
24605 combo_merge_btn.w = 20;
24606 combo_merge_btn.h = 20;
24607 combo_merge_btn.x = zq_screen_w-(combolist_window.w+combo_merge_btn.w)/2;
24608 combo_merge_btn.y = combolist[0].y-combo_merge_btn.h;
24609 squarepanel_swap_btn.clear();
24610 squarepanel_up_btn.clear();
24611 squarepanel_down_btn.clear();
24612
24613 drawmode_btn.x = combolist_window.x-drawmode_wid;
24614 drawmode_btn.y = 0;
24615 drawmode_btn.w = drawmode_wid;
24616 drawmode_btn.h = mapscreen_y;
24617
24618 compactbtn.w = text_length(guifont,"> Compact")+10;
24619 compactbtn.x = drawmode_btn.x-compactbtn.w;
24620 compactbtn.y = drawmode_btn.y;
24621 compactbtn.h = drawmode_btn.h;
24622
24623 zoominbtn.w = text_length(guifont,"+")+10;
24624 zoominbtn.x = compactbtn.x-zoominbtn.w;
24625 zoominbtn.y = compactbtn.y;
24626 zoominbtn.h = compactbtn.h;
24627
24628 zoomoutbtn.w = text_length(guifont,"-")+10;
24629 zoomoutbtn.x = zoominbtn.x-zoomoutbtn.w;
24630 zoomoutbtn.y = compactbtn.y;
24631 zoomoutbtn.h = compactbtn.h;
24632
24633 for(int32_t i=0; i<=8; i++)
24634 {
24635 map_page_bar[i].x = mapscreen_x+(i*16*2*mapscreen_screenunit_scale);
24636 map_page_bar[i].y = mapscreen_y+((13)*16*mapscreen_screenunit_scale);
24637 map_page_bar[i].w = 64;
24638 map_page_bar[i].h = text_height(guifont)+12;
24639 }
24640
24641 minimap.w=7+48*3;
24642 minimap.h=16+27*3;
24643
24644 layer_panel.x=map_page_bar[0].x;
24645 layer_panel.y=map_page_bar[0].y+map_page_bar[0].h;
24646 layer_panel.w=map_page_bar[8].x+map_page_bar[8].w;
24647 layer_panel.h=text_height(guifont)+8;
24648 layerpanel_buttonwidth = 58;
24649 layerpanel_buttonheight = layer_panel.h;
24650 layerpanel_checkbox_hei = layerpanel_buttonheight-4;
24651 layerpanel_checkbox_wid = 14;
24652
24653 commands_list.w=4;
24654 commands_window.w=commands_list.w*commands_list.xscale+16;
24655 commands_window.x=combolist_window.x-commands_window.w;
24656 commands_window.y=layer_panel.y+layer_panel.h;
24657 commands_window.h=zq_screen_h-commands_window.y;
24658
24659 //buttons panel
24660 main_panel.x = 0;
24661 main_panel.y = layer_panel.y+layer_panel.h;
24662 main_panel.w = commands_window.x - main_panel.x;
24663 main_panel.h = zq_screen_h - main_panel.y;
24664 preview_panel = main_panel;
24665
24666 preview_text.x = preview_panel.x+3;
24667 preview_text.y = preview_panel.y+3;
24668 preview_text.w = 1;
24669 preview_text.h = 12;
24670 preview_text.xscale = 10;
24671 preview_text.yscale = text_height(get_zc_font(font_lfont_l));
24672
24673 minimap.x=3;
24674 minimap.y=main_panel.y+4;
24675
24676 real_minimap.x = minimap.x+3;
24677 real_minimap.y = minimap.y+5;
24678 real_minimap.w = 16;
24679 real_minimap.h = 9;
24680 real_minimap.xscale = 9;
24681 real_minimap.yscale = 9;
24682 real_minimap.fw = real_minimap.xscale*8;
24683 real_minimap.fh = real_minimap.yscale*8;
24684
24685 int upscale_mm = 4;
24686 int xwid = real_minimap.tw()*(upscale_mm-1);
24687 int xhei = real_minimap.th()*(upscale_mm-1);
24688 int zh = minimap.h+xhei+4;
24689 minimap_zoomed.set(minimap.x, zq_screen_h-zh, minimap.w+xwid, zh);
24690 real_minimap_zoomed.set(minimap_zoomed.x+3, minimap_zoomed.y+5, real_minimap.w, real_minimap.h, real_minimap.xscale*upscale_mm, real_minimap.yscale*upscale_mm);
24691 real_minimap_zoomed.fw = real_minimap_zoomed.xscale*8;
24692 real_minimap_zoomed.fh = real_minimap_zoomed.yscale*8;
24693
24694 screrrorpos.x = 575;
24695 screrrorpos.y = 388;
24696
24697 mouse_scroll_h=10;
24698
24699 favorites_list.x=favorites_window.x+8;
24700 favorites_list.y=favorites_window.y+16;
24701 favorites_list.xscale = 16;
24702 favorites_list.yscale = 16;
24703 favorites_list.w=(favorites_window.w-16)/favorites_list.xscale;
24704 favorites_list.h=(favorites_window.h-24)/favorites_list.yscale;
24705
24706 int bh = 16;
24707 int by = commands_window.y+4;
24708 commands_list.y=by+bh;
24709 commands_list.h=(zq_screen_h - commands_list.y) / commands_list.yscale;
24710 commands_list.x=commands_window.x+8;
24711
24712 commands_x.w = 20;
24713 commands_x.h = bh;
24714 commands_x.x = commands_list.x + commands_list.tw() - commands_x.w;
24715 commands_x.y = by;
24716
24717 commands_infobtn.w = 20;
24718 commands_infobtn.h = bh;
24719 commands_infobtn.x = commands_x.x - commands_infobtn.w;
24720 commands_infobtn.y = by;
24721
24722 commands_zoombtn.w = 20;
24723 commands_zoombtn.h = bh;
24724 commands_zoombtn.x = commands_infobtn.x - commands_zoombtn.w;
24725 commands_zoombtn.y = by;
24726
24727 commands_txt.x = commands_list.x;
24728 commands_txt.y = by+(bh-text_height(get_zc_font(font_lfont_l)))/2;
24729
24730 favorites_x.x = favorites_window.x + favorites_window.w - favorites_x.w - 2;
24731 favorites_x.y = favorites_list.y-15;
24732
24733 favorites_infobtn.x = favorites_x.x - favorites_infobtn.w;
24734 favorites_infobtn.y = favorites_x.y;
24735
24736 favorites_zoombtn.x = favorites_infobtn.x - favorites_zoombtn.w;
24737 favorites_zoombtn.y = favorites_infobtn.y;
24738
24739 favorites_pgright.x = favorites_zoombtn.x - favorites_pgright.w;
24740 favorites_pgright.y = favorites_zoombtn.y;
24741
24742 favorites_pgleft.x = favorites_pgright.x - favorites_pgleft.w;
24743 favorites_pgleft.y = favorites_pgleft.y;
24744
24745 txtoffs_single.x = 22;
24746 txtoffs_single.y = 6;
24747 txtoffs_double_1.x = 22;
24748 txtoffs_double_1.y = 2;
24749 txtoffs_double_2.x = 22;
24750 txtoffs_double_2.y = 10;
24751 panel_align = 0;
24752
24753 int sqx = minimap.x+minimap.tw();
24754 squares_panel.set(sqx,main_panel.y,main_panel.tw()-sqx,main_panel.th());
24755 int x2 = sqx+4;
24756 int x1 = x2 - (20+(8*3)+2);
24757 int y1 = main_panel.y+10;
24758 int sw = 20, sh = 20;
24759 int offs = sh+4;
24760
24761 itemsqr_pos.set(x2,y1+(0*offs),sw,sh);
24762 flagsqr_pos.set(x2,y1+(1*offs),sw,sh);
24763 stairsqr_pos.set(x2,y1+(2*offs),sw,sh);
24764 warparrival_pos.set(x2,y1+(6*offs),sw,sh);
24765
24766 enemy_prev_pos.x = main_panel.x+14;
24767 enemy_prev_pos.y = main_panel.y+12 + minimap.h;
24768 enemy_prev_pos.w = 4;
24769 enemy_prev_pos.h = 3;
24770 enemy_prev_pos.xscale = 16;
24771 enemy_prev_pos.yscale = 16;
24772 enemy_prev_pos.fw = enemy_prev_pos.xscale*2;
24773 enemy_prev_pos.fh = enemy_prev_pos.yscale*2;
24774
24775 warpret_pos[0].set(x1,y1+(4*offs),sw,sh);
24776 warpret_pos[1].set(x1,y1+(5*offs),sw,sh);
24777 warpret_pos[2].set(x2,y1+(4*offs),sw,sh);
24778 warpret_pos[3].set(x2,y1+(5*offs),sw,sh);
24779
24780 auto& last_alias_list = comboaliaslist[num_combo_cols-1];
24781 combopool_preview.x=comboaliaslist[0].x;
24782 combopool_preview.y=last_alias_list.y+(last_alias_list.h*last_alias_list.yscale)+16;
24783 combopool_preview.w=(last_alias_list.x+(last_alias_list.w*last_alias_list.xscale))-comboaliaslist[0].x;
24784 combopool_preview.h=(favorites_window.y-combopool_preview.y);//+favorites_window.h-10;
24785 combopool_preview.w -= combopool_preview.w%16;
24786 combopool_preview.h -= combopool_preview.h%16;
24787
24788 FONT* tfont = get_zc_font(font_lfont_l);
24789 combopool_prevbtn.w = text_length(tfont, "Unweighted")+10;
24790 combopool_prevbtn.h = 11;
24791 combopool_prevbtn.x = combopool_preview.x;
24792 combopool_prevbtn.y = combopool_preview.y-combopool_prevbtn.h;
24793
24794 mappage_count = 9;
24795
24796 txfont = get_zc_font(font_lfont_l);
24797 combo_preview_text1.set(combo_preview.x-9,combo_preview.y,1,3,1,text_height(txfont));
24798 combo_preview_text2.set(combo_preview2.x+combo_preview2.w+8,combo_preview2.y,1,3,1,text_height(txfont));
24799
24800 favorites_x.w = 30;
24801 favorites_infobtn.w = 30;
24802 favorites_zoombtn.w = 30;
24803 favorites_pgleft.w = 30;
24804 favorites_pgright.w = 30;
24805 }
24806 //Same in all modes
24807 {
24808
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
8 if(is_compact ? compact_zoomed_cmd : large_zoomed_cmd)
24809 {
24810 8 commands_list.w /= 2;
24811 8 commands_list.xscale *= 2;
24812 8 }
24813
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
8 if(is_compact ? compact_zoomed_fav : large_zoomed_fav)
24814 {
24815
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(favorites_list.w%2)
24816 favorites_list.x += (favorites_list.xscale / 2);
24817 8 favorites_list.xscale *= 2;
24818 8 favorites_list.yscale *= 2;
24819 8 favorites_list.w /= 2;
24820 8 favorites_list.h /= 2;
24821 8 }
24822
24823 8 favorites_x.h = 14;
24824 8 favorites_x.x = favorites_window.x + favorites_window.w - favorites_x.w - 2;
24825 8 favorites_x.y = favorites_list.y-15;
24826
24827 8 favorites_infobtn.h = favorites_x.h;
24828 8 favorites_infobtn.x = favorites_x.x - favorites_infobtn.w;
24829 8 favorites_infobtn.y = favorites_x.y;
24830
24831 8 favorites_zoombtn.h = favorites_infobtn.h;
24832 8 favorites_zoombtn.x = favorites_infobtn.x - favorites_zoombtn.w;
24833 8 favorites_zoombtn.y = favorites_infobtn.y;
24834
24835 8 favorites_pgright.h = favorites_zoombtn.h;
24836 8 favorites_pgright.x = favorites_zoombtn.x - favorites_pgright.w;
24837 8 favorites_pgright.y = favorites_zoombtn.y;
24838
24839 8 favorites_pgleft.h = favorites_pgright.h;
24840 8 favorites_pgleft.x = favorites_pgright.x - favorites_pgleft.w;
24841 8 favorites_pgleft.y = favorites_pgright.y;
24842
24843 8 mainbar.x = dialogs[0].x+dialogs[0].w;
24844 8 mainbar.y = 0;
24845 8 mainbar.w = zoomoutbtn.x-mainbar.x;
24846 8 mainbar.h = drawmode_btn.h;
24847 }
24848
24849 //Ensure current combo list selected is valid
24850 8 current_combolist=vbound(current_combolist,0,num_combo_cols-1);
24851 8 current_comboalist=vbound(current_comboalist,0,num_combo_cols-1);
24852 8 current_cpoollist=vbound(current_cpoollist,0,num_combo_cols-1);
24853 8 current_cautolist = vbound(current_cautolist, 0, num_combo_cols - 1);
24854
24855 //Generate bitmaps
24856 8 init_bitmap(&mapscreenbmp,16*(showedges?18:16),16*(showedges?13:11));
24857 8 init_bitmap(&brushbmp,256*mapscreen_screenunit_scale,176*mapscreen_screenunit_scale);
24858 8 init_bitmap(&brushscreen,(256+(showedges?16:0))*mapscreen_screenunit_scale,(176+(showedges?16:0))*mapscreen_screenunit_scale);
24859
24860 8 init_bitmap(&screen2,zq_screen_w,zq_screen_h);
24861 8 init_bitmap(&tmp_scr,zq_screen_w,zq_screen_h);
24862 8 init_bitmap(&menu1,zq_screen_w,zq_screen_h);
24863 8 init_bitmap(&menu3,zq_screen_w,zq_screen_h);
24864
24865 8 center_zq_class_dialogs();
24866 8 center_zq_files_dialogs();
24867 8 center_zq_subscreen_dialogs();
24868 8 center_zq_tiles_dialogs();
24869 8 center_zquest_dialogs();
24870
24871 8 aspect_ratio = zq_screen_h / double(zq_screen_w);
24872
24873 8 mmap_init();
24874 8 }
24875
24876 11 void remove_locked_params_on_exit()
24877 {
24878 11 al_trace("Removing timers. \n");
24879 11 remove_int(fps_callback);
24880 11 remove_int(dclick_check);
24881 11 }
24882
24883 11 void destroy_bitmaps_on_exit()
24884 {
24885 11 al_trace("Cleaning bitmaps...");
24886 11 destroy_bitmap(screen2);
24887 11 destroy_bitmap(tmp_scr);
24888 11 destroy_bitmap(menu1);
24889 11 destroy_bitmap(menu3);
24890 11 destroy_bitmap(mapscreenbmp);
24891 11 destroy_bitmap(dmapbmp_small);
24892 11 destroy_bitmap(dmapbmp_large);
24893 11 destroy_bitmap(brushbmp);
24894 11 destroy_bitmap(brushscreen);
24895 11 al_trace("...");
24896
24897
2/2
✓ Branch 0 taken 528 times.
✓ Branch 1 taken 11 times.
539 for(int32_t i=0; i<MOUSE_BMP_MAX*4; i++)
24898 {
24899 528 destroy_bitmap(mouse_bmp[i/4][i%4]);
24900 528 destroy_bitmap(mouse_bmp_1x[i/4][i%4]);
24901 528 }
24902
24903
2/2
✓ Branch 0 taken 352 times.
✓ Branch 1 taken 11 times.
363 for(int32_t i=0; i<ICON_BMP_MAX*4; i++)
24904 352 destroy_bitmap(icon_bmp[i/4][i%4]);
24905
24906
2/2
✓ Branch 0 taken 704 times.
✓ Branch 1 taken 11 times.
715 for(int32_t i=0; i<16*4; i++)
24907 704 destroy_bitmap(flag_bmp[i/4][i%4]);
24908
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 11 times.
33 for(int32_t i=0; i<2; i++)
24909 22 destroy_bitmap(select_bmp[i]);
24910
24911
2/2
✓ Branch 0 taken 88 times.
✓ Branch 1 taken 11 times.
99 for(int32_t i=0; i<MAXARROWS; i++)
24912 88 destroy_bitmap(arrow_bmp[i]);
24913
24914 11 al_trace(" OK. \n");
24915 11 }
24916
24917
24918 11 void quit_game()
24919 {
24920 11 set_last_timed_save(nullptr);
24921 11 save_config_file();
24922 11 zc_set_palette(black_palette);
24923 11 zc_stop_midi();
24924
24925 11 remove_locked_params_on_exit();
24926
24927 11 al_trace("Cleaning sfx. \n");
24928
24929
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<WAV_COUNT; i++)
24930 {
24931
2/2
✓ Branch 0 taken 2805 times.
✓ Branch 1 taken 11 times.
2816 if(customsfxdata[i].data!=NULL)
24932 {
24933 // delete [] customsfxdata[i].data;
24934 2805 free(customsfxdata[i].data);
24935 2805 }
24936
24937
1/2
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
2816 delete [] sfx_string[i];
24938 2816 }
24939
24940
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<MAXWPNS; i++)
24941 {
24942
1/2
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
2816 delete [] weapon_string[i];
24943 2816 }
24944
24945
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<MAXITEMS; i++)
24946 {
24947
1/2
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
2816 delete [] item_string[i];
24948 2816 }
24949
24950
2/2
✓ Branch 0 taken 5632 times.
✓ Branch 1 taken 11 times.
5643 for(int32_t i=0; i<eMAXGUYS; i++)
24951 {
24952
1/2
✓ Branch 0 taken 5632 times.
✗ Branch 1 not taken.
5632 delete [] guy_string[i];
24953 5632 }
24954
24955 11 al_trace("Cleaning script buffer. \n");
24956
24957
2/2
✓ Branch 0 taken 5632 times.
✓ Branch 1 taken 11 times.
5643 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
24958 {
24959
2/4
✓ Branch 0 taken 5632 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5632 times.
5632 if(ffscripts[i]!=NULL) delete ffscripts[i];
24960 5632 }
24961
24962
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
24963 {
24964
2/4
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2816 times.
2816 if(itemscripts[i]!=NULL) delete itemscripts[i];
24965 2816 }
24966
24967
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
24968 {
24969
2/4
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2816 times.
2816 if(guyscripts[i]!=NULL) delete guyscripts[i];
24970 2816 }
24971
24972
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
24973 {
24974
2/4
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2816 times.
2816 if(lwpnscripts[i]!=NULL) delete lwpnscripts[i];
24975 2816 }
24976
24977
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
24978 {
24979
2/4
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2816 times.
2816 if(ewpnscripts[i]!=NULL) delete ewpnscripts[i];
24980 2816 }
24981
24982
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
24983 {
24984
2/4
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2816 times.
2816 if(screenscripts[i]!=NULL) delete screenscripts[i];
24985 2816 }
24986
24987
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 11 times.
44 for(int32_t i=0; i<3; i++) //should this be NUMSCRIPTGLOBAL or NUMSCRIPTGLOBALOLD? -Z
24988 {
24989
2/4
✓ Branch 0 taken 33 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 33 times.
33 if(globalscripts[i]!=NULL) delete globalscripts[i];
24990 33 }
24991
24992
2/2
✓ Branch 0 taken 55 times.
✓ Branch 1 taken 11 times.
66 for(int32_t i=0; i<NUMSCRIPTHERO; i++)
24993 {
24994
2/4
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 55 times.
55 if(playerscripts[i]!=NULL) delete playerscripts[i];
24995 55 }
24996
24997
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
24998 {
24999
2/4
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2816 times.
2816 if(dmapscripts[i]!=NULL) delete dmapscripts[i];
25000 2816 }
25001
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
25002 {
25003
2/4
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2816 times.
2816 if(itemspritescripts[i]!=NULL) delete itemspritescripts[i];
25004 2816 }
25005
2/2
✓ Branch 0 taken 5632 times.
✓ Branch 1 taken 11 times.
5643 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
25006 {
25007
2/4
✓ Branch 0 taken 5632 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5632 times.
5632 if(comboscripts[i]!=NULL) delete comboscripts[i];
25008 5632 }
25009
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 2816 times.
2827 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
25010 {
25011
2/4
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2816 times.
2816 if(subscreenscripts[i]!=NULL) delete subscreenscripts[i];
25012 2816 }
25013
25014 11 al_trace("Cleaning qst buffers. \n");
25015 11 del_qst_buffers();
25016
25017
25018 11 al_trace("Cleaning midis. \n");
25019
25020
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(customtunes)
25021 {
25022
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<MAXCUSTOMMIDIS_ZQ; i++)
25023 2816 customtunes[i].reset();
25024
25025 11 free(customtunes);
25026 11 }
25027
25028 11 al_trace("Cleaning undotilebuf. \n");
25029
25030 11 undocombobuf.clear();
25031
25032
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 3 times.
11 if(newundotilebuf)
25033 {
25034
2/2
✓ Branch 0 taken 1716000 times.
✓ Branch 1 taken 8 times.
1716008 for(int32_t i=0; i<NEWMAXTILES; i++)
25035
1/2
✓ Branch 0 taken 1716000 times.
✗ Branch 1 not taken.
1716000 if(newundotilebuf[i].data) free(newundotilebuf[i].data);
25036
25037 8 free(newundotilebuf);
25038 8 }
25039
25040
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(filepath) free(filepath);
25041
25042
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(datapath) free(datapath);
25043
25044
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(midipath) free(midipath);
25045
25046
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(imagepath) free(imagepath);
25047
25048
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(tmusicpath) free(tmusicpath);
25049
25050
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(last_timed_save) free(last_timed_save);
25051
25052 11 destroy_bitmaps_on_exit();
25053 11 }
25054
25055 void quit_game2()
25056 {
25057 set_last_timed_save(nullptr);
25058 save_config_file();
25059 zc_set_palette(black_palette);
25060 zc_stop_midi();
25061
25062 remove_locked_params_on_exit();
25063
25064 al_trace("Cleaning sfx. \n");
25065
25066 for(int32_t i=0; i<WAV_COUNT; i++)
25067 {
25068 if(customsfxdata[i].data!=NULL)
25069 {
25070 // delete [] customsfxdata[i].data;
25071 free(customsfxdata[i].data);
25072 }
25073
25074 delete [] sfx_string[i];
25075 }
25076
25077 for(int32_t i=0; i<MAXWPNS; i++)
25078 {
25079 delete [] weapon_string[i];
25080 }
25081
25082 for(int32_t i=0; i<MAXITEMS; i++)
25083 {
25084 delete [] item_string[i];
25085 }
25086
25087 for(int32_t i=0; i<eMAXGUYS; i++)
25088 {
25089 delete [] guy_string[i];
25090 }
25091
25092 al_trace("Cleaning script buffer. \n");
25093
25094 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
25095 {
25096 if(ffscripts[i]!=NULL) delete ffscripts[i];
25097 }
25098
25099 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
25100 {
25101 if(itemscripts[i]!=NULL) delete itemscripts[i];
25102 }
25103
25104 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
25105 {
25106 if(guyscripts[i]!=NULL) delete guyscripts[i];
25107 }
25108
25109 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
25110 {
25111 if(lwpnscripts[i]!=NULL) delete lwpnscripts[i];
25112 }
25113
25114 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
25115 {
25116 if(ewpnscripts[i]!=NULL) delete ewpnscripts[i];
25117 }
25118
25119 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
25120 {
25121 if(screenscripts[i]!=NULL) delete screenscripts[i];
25122 }
25123
25124 for(int32_t i=0; i<3; i++) //should this be NUMSCRIPTGLOBAL or NUMSCRIPTGLOBALOLD? -Z
25125 {
25126 if(globalscripts[i]!=NULL) delete globalscripts[i];
25127 }
25128
25129 for(int32_t i=0; i<NUMSCRIPTHERO; i++)
25130 {
25131 if(playerscripts[i]!=NULL) delete playerscripts[i];
25132 }
25133
25134 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
25135 {
25136 if(dmapscripts[i]!=NULL) delete dmapscripts[i];
25137 }
25138 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
25139 {
25140 if(itemspritescripts[i]!=NULL) delete itemspritescripts[i];
25141 }
25142 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
25143 {
25144 if(comboscripts[i]!=NULL) delete comboscripts[i];
25145 }
25146 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
25147 {
25148 if(subscreenscripts[i]!=NULL) delete subscreenscripts[i];
25149 }
25150
25151 al_trace("Cleaning qst buffers. \n");
25152 del_qst_buffers();
25153
25154
25155 al_trace("Cleaning midis. \n");
25156
25157 if(customtunes)
25158 {
25159 for(int32_t i=0; i<MAXCUSTOMMIDIS_ZQ; i++)
25160 customtunes[i].reset();
25161
25162 free(customtunes);
25163 }
25164
25165 al_trace("Cleaning undotilebuf. \n");
25166
25167 undocombobuf.clear();
25168
25169 if(newundotilebuf)
25170 {
25171 for(int32_t i=0; i<NEWMAXTILES; i++)
25172 if(newundotilebuf[i].data) free(newundotilebuf[i].data);
25173
25174 free(newundotilebuf);
25175 }
25176
25177 if(filepath) free(filepath);
25178
25179 if(datapath) free(datapath);
25180
25181 if(midipath) free(midipath);
25182
25183 if(imagepath) free(imagepath);
25184
25185 if(tmusicpath) free(tmusicpath);
25186
25187 if(last_timed_save) free(last_timed_save);
25188 }
25189
25190 8 void center_zquest_dialogs()
25191 {
25192 8 jwin_center_dialog(assignscript_dlg);
25193 8 jwin_center_dialog(autolayer_dlg);
25194 8 center_zq_cset_dialogs();
25195 8 jwin_center_dialog(change_track_dlg);
25196 8 jwin_center_dialog(csetfix_dlg);
25197 8 jwin_center_dialog(dmapmaps_dlg);
25198 8 center_zq_door_dialogs();
25199 8 jwin_center_dialog(editcomboa_dlg);
25200 8 jwin_center_dialog(editinfo_dlg);
25201 8 jwin_center_dialog(editmusic_dlg);
25202 8 jwin_center_dialog(editshop_dlg);
25203 8 jwin_center_dialog(ffcombo_sel_dlg);
25204 8 jwin_center_dialog(getnum_dlg);
25205 8 jwin_center_dialog(layerdata_dlg);
25206 8 jwin_center_dialog(list_dlg);
25207 8 jwin_center_dialog(loadmap_dlg);
25208 8 jwin_center_dialog(misccolors_dlg);
25209 8 jwin_center_dialog(newcomboa_dlg);
25210 8 jwin_center_dialog(orgcomboa_dlg);
25211 8 jwin_center_dialog(path_dlg);
25212 8 jwin_center_dialog(screen_pal_dlg);
25213 8 jwin_center_dialog(secret_dlg);
25214 8 jwin_center_dialog(selectmusic_dlg);
25215 8 jwin_center_dialog(showpal_dlg);
25216 8 jwin_center_dialog(strlist_dlg);
25217 8 jwin_center_dialog(template_dlg);
25218 8 jwin_center_dialog(tp_dlg);
25219 8 jwin_center_dialog(under_dlg);
25220 8 jwin_center_dialog(tilewarp_dlg);
25221 8 jwin_center_dialog(sidewarp_dlg);
25222 8 jwin_center_dialog(warpring_dlg);
25223 8 center_zscript_dialogs();
25224 8 }
25225
25226
25227 void animate_coords()
25228 {
25229 coord_frame=(coord_timer>>3)&3;
25230
25231 if(++coord_timer>=(1<<5))
25232 {
25233 coord_timer=0;
25234 }
25235 }
25236
25237 static const char *help_list[] =
25238 {
25239 "PREVIEW MODE",
25240 "PgUp/PgDn - Scroll through hotkey list",
25241 "Esc/Enter - Exit Preview Mode",
25242 "R - Restore screen to original state",
25243 "C - Toggle combo cycling On/Off",
25244 "S - Trigger screen secrets",
25245 "Q/W/F - These still work",
25246 "P - Pause everything",
25247 "A - Advance frame-by-frame",
25248 "1-4 - Trigger tile warp A-D",
25249 "5-8 - Trigger side warp A-D",
25250 "9 - Enable timed warps",
25251 "",
25252 "",
25253 };
25254
25255 void do_previewtext()
25256 {
25257 FONT* oldfont = font;
25258 font = get_zc_font(font_lfont_l);
25259
25260 //Put in help areas
25261 auto& sqr = preview_text;
25262 int ind = 0, len = 0;
25263 for(int q = 0; q < 12; ++q)
25264 {
25265 int l = text_length(font, help_list[q]);
25266 if(len < l) len = l;
25267 }
25268 sqr.xscale = len+2;
25269 sqr.yscale = text_height(font);
25270 for(int col = 0; col < sqr.w; ++col)
25271 {
25272 for(int row = 0; row < sqr.h; ++row)
25273 {
25274 auto& line = sqr.subsquare(col,row);
25275 textprintf_ex(menu1,font,line.x,line.y,jwin_pal[jcTEXTFG],-1,"%s",help_list[ind++]);
25276 }
25277 }
25278
25279 font = oldfont;
25280 }
25281
25282
25283 bool reload_fonts = false;
25284 void run_zq_frame()
25285 {
25286 if(reload_fonts)
25287 {
25288 init_custom_fonts();
25289 load_size_poses();
25290 reload_fonts = false;
25291 }
25292
25293 domouse();
25294 custom_vsync();
25295 refresh(rCLEAR|rALL);
25296 }
25297 8 int32_t d_nbmenu_proc(int32_t msg,DIALOG *d,int32_t c)
25298 {
25299
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
8 switch(msg)
25300 {
25301 case MSG_VSYNC:
25302 run_zq_frame();
25303 break;
25304 case MSG_GOTMOUSE:
25305 case MSG_XCHAR:
25306 ComboBrushPause=1;
25307 refresh(rMAP);
25308 ComboBrushPause=0;
25309 clear_tooltip();
25310 break;
25311 }
25312
25313 8 return GuiMenu::proc(msg,d,c);
25314 }
25315
25316 bool prv_press=false;
25317
25318 void dopreview()
25319 {
25320 refresh(rMAP);
25321
25322 while(!(gui_mouse_b()))
25323 {
25324 if(keypressed())
25325 {
25326 if(!prv_press)
25327 {
25328 prv_press=true;
25329
25330 switch(readkey()>>8)
25331 {
25332 case KEY_ESC:
25333 case KEY_ENTER:
25334 case KEY_ENTER_PAD:
25335 goto finished;
25336 break;
25337
25338 case KEY_F:
25339 Flags^=cFLAGS;
25340 refresh(rMAP);
25341 break;
25342
25343 case KEY_R:
25344 onReloadPreview();
25345 break;
25346
25347 case KEY_S:
25348 onSecretsPreview();
25349 break;
25350
25351 case KEY_C:
25352 onCopy();
25353 break;
25354
25355 case KEY_A:
25356 onAKey();
25357 break;
25358
25359 case KEY_P:
25360 onP();
25361 break;
25362
25363 case KEY_L:
25364 onShowDarkness();
25365 break;
25366
25367 case KEY_1:
25368 Map.prv_dowarp(0,0);
25369 prv_warp=0;
25370 break;
25371
25372 case KEY_2:
25373 Map.prv_dowarp(0,1);
25374 prv_warp=0;
25375 break;
25376
25377 case KEY_3:
25378 Map.prv_dowarp(0,2);
25379 prv_warp=0;
25380 break;
25381
25382 case KEY_4:
25383 Map.prv_dowarp(0,3);
25384 prv_warp=0;
25385 break;
25386
25387 case KEY_5:
25388 Map.prv_dowarp(1,0);
25389 prv_warp=0;
25390 break;
25391
25392 case KEY_6:
25393 Map.prv_dowarp(1,1);
25394 prv_warp=0;
25395 break;
25396
25397 case KEY_7:
25398 Map.prv_dowarp(1,2);
25399 prv_warp=0;
25400 break;
25401
25402 case KEY_8:
25403 Map.prv_dowarp(1,3);
25404 prv_warp=0;
25405 break;
25406
25407 case KEY_9:
25408 if(prv_twon)
25409 {
25410 prv_twon=0;
25411 Map.set_prvtime(0);
25412 prv_warp=0;
25413 }
25414 else
25415 {
25416 Map.set_prvtime(Map.get_prvscr()->timedwarptics);
25417 prv_twon=1;
25418 }
25419
25420 break;
25421
25422 case KEY_W:
25423 onShowWalkability();
25424 break;
25425
25426 case KEY_Q:
25427 onShowComboInfoCSet();
25428 break;
25429 }
25430 }
25431 else
25432 {
25433 readkey();
25434 }
25435 }
25436 else
25437 {
25438 prv_press=false;
25439 }
25440
25441 if(prv_warp)
25442 {
25443 Map.prv_dowarp(1,0);
25444 prv_warp=0;
25445 }
25446
25447 if(Map.get_prvfreeze())
25448 {
25449 if(Map.get_prvadvance())
25450 {
25451 custom_vsync();
25452 Map.set_prvadvance(0);
25453 }
25454 }
25455 else
25456 {
25457 custom_vsync();
25458 Map.set_prvadvance(0);
25459 }
25460
25461 refresh(rALL);
25462 }
25463
25464 finished:
25465 //Flags=of;
25466 reset_combo_animations();
25467 reset_combo_animations2();
25468 MouseSprite::set(ZQM_NORMAL);
25469 prv_mode=0;
25470 prv_warp=0;
25471 Map.end_prv();
25472 Map.refresh_color();
25473 refresh(rMAP+rMENU);
25474
25475 while(gui_mouse_b())
25476 {
25477 /* do nothing */
25478 rest(1);
25479 }
25480 }
25481
25482 void call_vidmode_dlg();
25483 int32_t onZQVidMode()
25484 {
25485 call_vidmode_dlg();
25486 return D_O_K;
25487 }
25488
25489 bool screenIsScrolling()
25490 {
25491 return false;
25492 }
25493
25494 void write_includepaths()
25495 {
25496 FILE* f = fopen("includepaths.txt", "w");
25497 if(f)
25498 {
25499 fwrite(FFCore.includePathString,1,strlen(FFCore.includePathString),f);
25500 fclose(f);
25501 }
25502 }
25503
25504 11 int32_t save_config_file()
25505 {
25506
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (!application_has_loaded) return 0;
25507
25508 char qtnametitle[20];
25509 char qtpathtitle[20];
25510 char *datapath2=(char *)malloc(2048);
25511 char *midipath2=(char *)malloc(2048);
25512 char *imagepath2=(char *)malloc(2048);
25513 char *tmusicpath2=(char *)malloc(2048);
25514 strcpy(datapath2, datapath);
25515 strcpy(midipath2, midipath);
25516 strcpy(imagepath2, imagepath);
25517 strcpy(tmusicpath2, tmusicpath);
25518 chop_path(datapath2);
25519 chop_path(midipath2);
25520 chop_path(imagepath2);
25521 chop_path(tmusicpath2);
25522 write_includepaths();
25523
25524 zc_set_config("zquest",data_path_name,datapath2);
25525 zc_set_config("zquest",midi_path_name,midipath2);
25526 zc_set_config("zquest",image_path_name,imagepath2);
25527 zc_set_config("zquest",tmusic_path_name,tmusicpath2);
25528
25529 if (all_get_display() && !all_get_fullscreen_flag() && SaveDragResize)
25530 {
25531 window_width = al_get_display_width(all_get_display());
25532 window_height = al_get_display_height(all_get_display());
25533 zc_set_config("zquest","window_width",window_width);
25534 zc_set_config("zquest","window_height",window_height);
25535 }
25536 if (all_get_display() && !all_get_fullscreen_flag() && SaveWinPos)
25537 {
25538 int o_window_x, o_window_y;
25539 al_get_window_position(all_get_display(), &o_window_x, &o_window_y);
25540 zc_set_config("zquest", "window_x", o_window_x);
25541 zc_set_config("zquest", "window_y", o_window_y);
25542 }
25543
25544 byte b = 0;
25545 for(int32_t x=0; x<7; x++)
25546 {
25547 set_bit(&b,x,LayerMaskInt[x]);
25548 }
25549
25550 zc_set_config("zquest","layer_mask",b);
25551
25552 flush_config_file();
25553 #ifdef __EMSCRIPTEN__
25554 em_sync_fs();
25555 #endif
25556 free(datapath2);
25557 free(midipath2);
25558 free(imagepath2);
25559 free(tmusicpath2);
25560 return 0;
25561 11 }
25562
25563 int32_t d_timer_proc(int32_t msg, DIALOG *d, int32_t c)
25564 {
25565 //these are here to bypass compiler warnings about unused arguments
25566 c=c;
25567 d=d;
25568
25569 switch(msg)
25570 {
25571 case MSG_IDLE:
25572 #ifdef _WIN32
25573 if(zqUseWin32Proc != FALSE)
25574 win32data.Update(Frameskip); //experimental win32 fixes
25575
25576 #endif
25577
25578 // This has been crashing on Windows, and it saves plenty without it
25579 //check_autosave();
25580 break;
25581 }
25582
25583 return D_O_K;
25584 }
25585
25586 void check_autosave()
25587 {
25588 if (!first_save)
25589 return;
25590
25591 if(AutoSaveInterval>0)
25592 {
25593 time(&auto_save_time_current);
25594 auto_save_time_diff = difftime(auto_save_time_current,auto_save_time_start);
25595
25596 if(auto_save_time_diff>AutoSaveInterval*60)
25597 {
25598 MouseSprite::set(ZQM_NORMAL);
25599 replace_extension(last_timed_save, filepath, "qt0", 2047);
25600 set_last_timed_save(last_timed_save);
25601 go();
25602
25603 if((header.zelda_version != ZELDA_VERSION || header.build != VERSION_BUILD))
25604 {
25605 jwin_alert("Auto Save","This quest was saved in an older version of ZQuest.","If you wish to use the autosave feature, you must manually","save the files in this version first.","OK",NULL,13,27,get_zc_font(font_lfont));
25606 time(&auto_save_time_start);
25607 comeback();
25608 return;
25609 }
25610
25611 int32_t ret = save_quest(last_timed_save, true);
25612
25613 if(ret)
25614 {
25615 jwin_alert("Error","Timed save did not complete successfully.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
25616 set_last_timed_save(nullptr);
25617 }
25618
25619 save_config_file();
25620 time(&auto_save_time_start);
25621 comeback();
25622 }
25623 }
25624 }
25625
25626 void flushItemCache(bool) {}
25627 void ringcolor(bool forceDefault)
25628 {
25629 forceDefault=forceDefault;
25630 }
25631
25632 bool item_disabled(int32_t)
25633 {
25634 return false;
25635 }
25636
25637 int32_t onCmdExit()
25638 {
25639 // replaces onExit for the -large button command "Exit"
25640 close_button_quit = true;
25641 return 0;
25642 }
25643
25644 int32_t onQuickCompile()
25645 {
25646 if(do_compile_and_slots(1,false))
25647 {
25648 saved = false;
25649 InfoDialog("Quick Compile","Success!").show();
25650 }
25651 else
25652 {
25653 InfoDialog("Quick Compile","Failure!").show();
25654 }
25655 return 0;
25656 }
25657 int32_t onSmartCompile()
25658 {
25659 if(do_compile_and_slots(2,false))
25660 {
25661 saved = false;
25662 InfoDialog("Smart Compile","Success!").show();
25663 }
25664 else
25665 {
25666 InfoDialog("Smart Compile","Failure!").show();
25667 }
25668 return 0;
25669 }
25670
25671 int32_t strchrnum(char const* str, char c)
25672 {
25673 for(int32_t i=0; str[i]; ++i)
25674 {
25675 if(str[i]==c)
25676 {
25677 return i;
25678 }
25679 }
25680
25681 return -1;
25682 }
25683
25684 int32_t get_longest_line_length(FONT *f, char* str)
25685 {
25686 int32_t maxlen=0;
25687 char* tmpstr = str;
25688 char temp=0;
25689 int32_t t=0;
25690 int32_t new_t=-1;
25691 while(tmpstr[0])
25692 {
25693 t=strchrnum(tmpstr, '\n');
25694
25695 if(t==-1)
25696 {
25697 t=(int32_t)strlen(tmpstr);
25698 }
25699
25700 if((uint32_t)t!=strlen(tmpstr))
25701 {
25702 new_t=t+1;
25703 }
25704 else
25705 {
25706 new_t=-1;
25707 }
25708
25709 temp = tmpstr[t];
25710 tmpstr[t]=0;
25711 maxlen=zc_max(maxlen,text_length(f, tmpstr));
25712 tmpstr[t]=temp;
25713
25714 if(new_t!=-1)
25715 {
25716 tmpstr+=new_t;
25717 }
25718 else break;
25719 }
25720 return maxlen;
25721 }
25722
25723 int32_t count_lines(char const* str)
25724 {
25725 int32_t count=1;
25726
25727 for(word i=0; i<strlen(str); ++i)
25728 {
25729 if(str[i]=='\n')
25730 {
25731 ++count;
25732 }
25733 }
25734
25735 return count;
25736 }
25737
25738 void debug_pos(size_and_pos const& pos, int color)
25739 {
25740 if(pos.w < 1 || pos.h < 1)
25741 return;
25742 if(pos.xscale > 1 || pos.yscale > 1)
25743 {
25744 auto maxind = pos.w*pos.h;
25745 for(auto q = 0; q < maxind; ++q)
25746 {
25747 auto& sub = pos.subsquare(q);
25748 if(sub.x < 0) break;
25749 highlight_sqr(screen, color, sub, 1);
25750 }
25751 }
25752 else
25753 {
25754 if(pos.fw > -1 && pos.fh > -1)
25755 highlight_frag(screen, color, pos, 1);
25756 else highlight_sqr(screen, color, pos, 1);
25757 }
25758 }
25759
25760 void textbox_out(BITMAP* dest, FONT* font, int x, int y, int fg, int bg, char const* str, int align, size_and_pos* dims)
25761 {
25762 static size_and_pos nilsz;
25763 size_and_pos& txbox = dims ? *dims : nilsz;
25764
25765 char* kill = (char*)malloc(strlen(str)+1);
25766 char *tmpstr = kill;
25767 strcpy(tmpstr,str);
25768
25769 while(tmpstr[0] == '\n')
25770 ++tmpstr;
25771 int len = strlen(tmpstr);
25772 while(tmpstr[len-1] == '\n')
25773 tmpstr[--len] = 0;
25774
25775 txbox.x=x;
25776 txbox.y=y;
25777 int32_t lines=count_lines(tmpstr);
25778 txbox.w = 1;
25779 txbox.h = lines;
25780 txbox.xscale = get_longest_line_length(font, tmpstr);
25781 txbox.yscale = text_height(font);
25782
25783 int ax = 0; //Aligned x
25784 switch(align)
25785 {
25786 case 0: //left
25787 break;
25788 case 1: //center
25789 txbox.x -= txbox.xscale/2;
25790 ax = txbox.xscale/2;
25791 break;
25792 case 2: //right
25793 txbox.x -= txbox.xscale;
25794 ax = txbox.xscale;
25795 break;
25796 }
25797
25798 int bw = txbox.w*txbox.xscale;
25799 int bh = txbox.h*txbox.yscale;
25800 BITMAP* outbmp = create_bitmap_ex(8, bw, bh);
25801 clear_to_color(outbmp, bg);
25802
25803 char temp = 0;
25804 int32_t t=0;
25805 int32_t new_t=-1;
25806 int32_t line=0;
25807
25808 while(tmpstr[t])
25809 {
25810 t=strchrnum(tmpstr, '\n');
25811
25812 if(t==-1)
25813 t=(int32_t)strlen(tmpstr);
25814
25815 if((uint32_t)t!=strlen(tmpstr))
25816 new_t=t+1;
25817 else
25818 new_t=-1;
25819
25820 temp = tmpstr[t];
25821 tmpstr[t]=0;
25822 gui_textout_ln(outbmp, font, (ucc*)tmpstr, ax, (line*txbox.yscale), fg, -1, align);
25823 tmpstr[t]=temp;
25824 ++line;
25825
25826 if(new_t!=-1)
25827 {
25828 tmpstr+=new_t;
25829 t=0;
25830 }
25831 }
25832
25833 blit(outbmp, dest, 0, 0, txbox.x, txbox.y, bw, bh);
25834 destroy_bitmap(outbmp);
25835 free(kill);
25836 }
25837
25838 void highlight_sqr(BITMAP* dest, int color, int x, int y, int w, int h, int thick)
25839 {
25840 for(int q = 0; q < thick; ++q)
25841 {
25842 safe_rect(dest, x+q, y+q, x+w-1-q, y+h-1-q, color);
25843 }
25844 }
25845 void highlight_sqr(BITMAP* dest, int color, size_and_pos const& rec, int thick)
25846 {
25847 highlight_sqr(dest, color, rec.x, rec.y, rec.tw(), rec.th(), thick);
25848 }
25849 void highlight_frag(BITMAP* dest, int color, int x1, int y1, int w, int h, int fw, int fh, int thick)
25850 {
25851 int xc = x1+fw-1;
25852 int yc = y1+fh-1;
25853 int x2 = x1+w-1;
25854 int y2 = y1+h-1;
25855
25856 hline(dest, x1, y1, x2, color);
25857 vline(dest, x1, y1, y2, color);
25858
25859 hline(dest, x1, y2, xc, color);
25860 vline(dest, x2, y1, yc, color);
25861 hline(dest, xc, yc, x2, color);
25862 vline(dest, xc, yc, y2, color);
25863 }
25864 void highlight_frag(BITMAP* dest, int color, size_and_pos const& rec, int thick)
25865 {
25866 highlight_frag(dest, color, rec.x, rec.y, rec.tw(), rec.th(), rec.fw, rec.fh, thick);
25867 }
25868
25869 void highlight(BITMAP* dest, size_and_pos& hl)
25870 {
25871 if(hl.fw > -1 && hl.fh > -1)
25872 {
25873 highlight_frag(dest, hl.data[1], hl, hl.data[0]);
25874 }
25875 else highlight_sqr(dest, hl.data[1], hl, hl.data[0]);
25876 }
25877
25878 std::pair<int, int> get_box_text_size(char const* tipmsg, double txscale)
25879 {
25880 if(txscale < 1) txscale = 1;
25881 char* kill = (char*)malloc(strlen(tipmsg)+1);
25882 char *tmpstr = kill;
25883 strcpy(tmpstr,tipmsg);
25884
25885 while(tmpstr[0] == '\n')
25886 ++tmpstr;
25887 int len = strlen(tmpstr);
25888 while(tmpstr[len-1] == '\n')
25889 tmpstr[--len] = 0;
25890
25891 int32_t lines = count_lines(tmpstr);
25892 int txlen = get_longest_line_length(font, tmpstr);
25893 int txhei = lines*text_height(font);
25894 int tx_sclen = (txlen * txscale);
25895 int tx_schei = (txhei * txscale);
25896 int w = tx_sclen + 8 + 1;
25897 int h = tx_schei + 8 + 1;
25898 if (w > zq_screen_w)
25899 w = zq_screen_w;
25900 if (h > zq_screen_h)
25901 h = zq_screen_h;
25902 return {w, h};
25903 }
25904
25905 void draw_box(BITMAP* destbmp, size_and_pos* pos, char const* tipmsg, double txscale)
25906 {
25907 if(txscale < 1) txscale = 1;
25908 char* kill = (char*)malloc(strlen(tipmsg)+1);
25909 char *tmpstr = kill;
25910 strcpy(tmpstr,tipmsg);
25911
25912 while(tmpstr[0] == '\n')
25913 ++tmpstr;
25914 int len = strlen(tmpstr);
25915 while(tmpstr[len-1] == '\n')
25916 tmpstr[--len] = 0;
25917
25918 auto& box = *pos;
25919 clear_bitmap(destbmp);
25920
25921 int32_t lines=count_lines(tmpstr);
25922 int txlen = get_longest_line_length(font, tmpstr);
25923 int txhei = lines*text_height(font);
25924 int tx_sclen = (txlen * txscale);
25925 int tx_schei = (txhei * txscale);
25926 box.w = tx_sclen + 8 + 1;
25927 box.h = tx_schei + 8 + 1;
25928 if (box.w > zq_screen_w)
25929 box.w = zq_screen_w;
25930 if (box.h > zq_screen_h)
25931 box.h = zq_screen_h;
25932
25933 if(box.x+box.w>=zq_screen_w)
25934 {
25935 box.x=(zq_screen_w - box.w);
25936 }
25937
25938 if(box.y+box.h>=zq_screen_h)
25939 {
25940 box.y=(zq_screen_h - box.h);
25941 }
25942
25943 rectfill(destbmp, 1, 1, box.w-3, box.h-3, jwin_pal[jcTEXTBG]);
25944 rect(destbmp, 0, 0, box.w-2, box.h-2, jwin_pal[jcTEXTFG]);
25945 vline(destbmp, box.w-1, 0, box.h-1, jwin_pal[jcTEXTFG]);
25946 hline(destbmp, 1, box.h-1, box.w-2, jwin_pal[jcTEXTFG]);
25947 destbmp->line[box.h-1][0]=0;
25948 destbmp->line[0][box.w-1]=0;
25949
25950 char temp = 0;
25951 int32_t t=0;
25952 int32_t new_t=-1;
25953 int32_t line=0;
25954
25955 BITMAP* txbmp = create_bitmap_ex(8,box.w,box.h);
25956 clear_bitmap(txbmp);
25957 while(tmpstr[t])
25958 {
25959 t=strchrnum(tmpstr, '\n');
25960
25961 if(t==-1)
25962 {
25963 t=(int32_t)strlen(tmpstr);
25964 }
25965
25966 if((uint32_t)t!=strlen(tmpstr))
25967 {
25968 new_t=t+1;
25969 }
25970 else
25971 {
25972 new_t=-1;
25973 }
25974
25975 temp = tmpstr[t];
25976 tmpstr[t]=0;
25977 textprintf_ex(txbmp, font, 0, (line*text_height(font)), jwin_pal[jcTEXTFG], -1, "%s", tmpstr);
25978 tmpstr[t]=temp;
25979 ++line;
25980
25981 if(new_t!=-1)
25982 {
25983 tmpstr+=new_t;
25984 t=0;
25985 }
25986 }
25987 masked_stretch_blit(txbmp,destbmp,0,0,txlen,txhei,4,4,tx_sclen,tx_schei);
25988 destroy_bitmap(txbmp);
25989 free(kill);
25990 }
25991
25992 void update_tooltip(int32_t x, int32_t y, size_and_pos const& sqr, char const* tipmsg, double scale)
25993 {
25994 update_tooltip(x,y,sqr.x,sqr.y,sqr.w*sqr.xscale,sqr.h*sqr.yscale,tipmsg,sqr.fw,sqr.fh,scale);
25995 }
25996 void update_tooltip(int32_t x, int32_t y, int32_t tx, int32_t ty, int32_t tw, int32_t th, char const* tipmsg, int fw, int fh, double scale)
25997 {
25998 if(!EnableTooltips)
25999 {
26000 return;
26001 }
26002
26003 ttip_install(ttip_global_id, tipmsg, tx, ty, tw, th, x, y, fw, fh);
26004 }
26005
26006 void ZQ_ClearQuestPath()
26007 {
26008 zc_set_config("zquest","win_last_quest",(char const*)nullptr);
26009 strcpy(filepath,"");
26010 }
26011
26012 //FFCore
26013
26014 void FFScript::init()
26015 {
26016 for ( int32_t q = 0; q < wexLast; q++ ) warpex[q] = 0;
26017 numscriptdraws = 0;
26018 max_ff_rules = qr_MAX;
26019 temp_no_stepforward = 0;
26020 nostepforward = 0;
26021
26022 coreflags = 0;
26023 skip_ending_credits = 0;
26024 music_update_cond = 0;
26025 music_update_flags = 0;
26026 for ( int32_t q = 0; q < susptLAST; q++ ) { system_suspend[q] = false; }
26027
26028 //for ( int32_t q = 0; q < 512; q++ ) FF_rules[q] = 0;
26029 int32_t usr_midi_volume = usr_digi_volume = usr_sfx_volume = usr_music_volume = usr_panstyle = 0;
26030 FF_hero_action = 0;
26031 enemy_removal_point[spriteremovalY1] = -32767;
26032 enemy_removal_point[spriteremovalY2] = 32767;
26033 enemy_removal_point[spriteremovalX1] = -32767;
26034 enemy_removal_point[spriteremovalX2] = 32767;
26035 enemy_removal_point[spriteremovalZ1] = -32767;
26036 enemy_removal_point[spriteremovalZ2] = 32767;
26037
26038 for ( int32_t q = 0; q < 4; q++ )
26039 {
26040 FF_screenbounds[q] = 0;
26041 FF_screen_dimensions[q] = 0;
26042 FF_subscreen_dimensions[q] = 0;
26043 FF_eweapon_removal_bounds[q] = 0;
26044 FF_lweapon_removal_bounds[q] = 0;
26045 }
26046 for ( int32_t q = 0; q < FFSCRIPTCLASS_CLOCKS; q++ )
26047 {
26048 FF_clocks[q] = 0;
26049 }
26050 for ( int32_t q = 0; q < SCRIPT_DRAWING_RULES; q++ )
26051 {
26052 ScriptDrawingRules[q] = 0;
26053 }
26054 for ( int32_t q = 0; q < NUM_USER_MIDI_OVERRIDES; q++ )
26055 {
26056 FF_UserMidis[q] = 0;
26057 }
26058 subscreen_scroll_speed = 0; //make a define for a default and read quest override! -Z
26059 kb_typing_mode = false;
26060 initIncludePaths();
26061 }
26062
26063 void FFScript::updateIncludePaths()
26064 {
26065 includePaths.clear();
26066 int32_t pos = 0; int32_t pathnumber = 0;
26067 for ( int32_t q = 0; includePathString[pos]; ++q )
26068 {
26069 int32_t dest = 0;
26070 char buf[2048] = {0};
26071 while(includePathString[pos] != ';' && includePathString[pos])
26072 {
26073 buf[dest] = includePathString[pos];
26074 ++pos;
26075 ++dest;
26076 }
26077 ++pos;
26078 string str(buf);
26079 includePaths.push_back(str);
26080 }
26081 }
26082
26083 void FFScript::initIncludePaths()
26084 {
26085 memset(includePathString,0,sizeof(includePathString));
26086 FILE* f = fopen("includepaths.txt", "r");
26087 if(f)
26088 {
26089 int32_t pos = 0;
26090 int32_t c;
26091 do
26092 {
26093 c = fgetc(f);
26094 if(c!=EOF)
26095 includePathString[pos++] = c;
26096 }
26097 while(c!=EOF && pos<MAX_INCLUDE_PATH_CHARS);
26098 if(pos<MAX_INCLUDE_PATH_CHARS)
26099 includePathString[pos] = '\0';
26100 includePathString[MAX_INCLUDE_PATH_CHARS-1] = '\0';
26101 fclose(f);
26102 }
26103 else strcpy(includePathString, "include/;headers/;scripts/;");
26104 al_trace("Full path string is: ");
26105 safe_al_trace(includePathString);
26106 al_trace("\n");
26107 updateIncludePaths();
26108
26109 for ( size_t q = 0; q < includePaths.size(); ++q )
26110 {
26111 al_trace("Include path %zu: ",q);
26112 safe_al_trace(includePaths.at(q).c_str());
26113 al_trace("\n");
26114 }
26115 }
26116
26117 int32_t FFScript::getQRBit(int32_t rule)
26118 {
26119 return ( get_qr(rule) ? 1 : 0 );
26120 }
26121
26122 int32_t FFScript::getTime(int32_t type)
26123 {
26124 //struct tm *tm_struct = localtime(time(NULL));
26125 struct tm * tm_struct;
26126 time_t rawtime;
26127 time (&rawtime);
26128 tm_struct = localtime (&rawtime);
26129
26130 switch(type)
26131 {
26132 case curyear:
26133 {
26134 int32_t year = tm_struct->tm_year + 1900; /* year */
26135 //year format starts at 1900, so we add it to the return
26136 return year;
26137
26138 }
26139 case curmonth:
26140 {
26141 int32_t month = tm_struct->tm_mon +1; /* month */
26142 //Months start at 0, but we want 1->12
26143 return month;
26144 }
26145 case curday_month:
26146 {
26147 int32_t day_month = tm_struct->tm_mday; /* day of the month */
26148 return day_month;
26149 }
26150 case curday_week:
26151 {
26152 int32_t day_week = tm_struct->tm_wday; /* day of the week */
26153 return day_week;
26154 }
26155 case curhour:
26156 {
26157 int32_t hour = tm_struct->tm_hour; /* hours */
26158 return hour;
26159 }
26160 case curminute:
26161 {
26162 int32_t minutes = tm_struct->tm_min; /* minutes */
26163 return minutes;
26164 }
26165 case cursecond:
26166 {
26167 int32_t secs = tm_struct->tm_sec; /* seconds */
26168 return secs;
26169 }
26170 case curdayyear:
26171 {
26172 int32_t day_year = tm_struct->tm_yday; /* day in the year */
26173 return day_year;
26174 }
26175 case curDST:
26176 {
26177 int32_t isDST = tm_struct->tm_isdst; /* daylight saving time */
26178 return isDST;
26179 }
26180 default: return -1;
26181
26182 }
26183 }
26184
26185 extern const char *itemclass_help_string_defaults[itype_max];
26186
26187 /* end */
26188
26189 24576 int32_t FFScript::getQuestHeaderInfo(int32_t type)
26190 {
26191 24576 return quest_format[type];
26192 }
26193
26194 bool isSideViewGravity(int32_t t)
26195 {
26196 return (Map.CurrScr()->flags7&fSIDEVIEW) != 0;
26197 }
26198
26199
26200
26201
26202 void FFScript::ZScriptConsole(bool open)
26203 {
26204
26205
26206 #ifdef _WIN32
26207 if ( console_is_open )
26208 {
26209 zscript_coloured_console.Create("ZQuest Classic Logging Console", 600, 200);
26210 zscript_coloured_console.cls(CConsoleLoggerEx::COLOR_BACKGROUND_BLACK);
26211 zscript_coloured_console.gotoxy(0,0);
26212 zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_BLUE | CConsoleLoggerEx::COLOR_INTENSITY |
26213 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"ZQuest Classic Logging Console\n");
26214 }
26215 else
26216 {
26217 //close
26218 zscript_coloured_console.Close();
26219 }
26220 #endif
26221 }
26222
26223 template <typename ...Params>
26224 void FFScript::ZScriptConsole(int32_t attributes,const char *format, Params&&... params)
26225 {
26226 #ifdef _WIN32
26227 initConsole();
26228 zscript_coloured_console.cprintf( attributes, format, std::forward<Params>(params)... );
26229 #endif
26230 }
26231
26232 int32_t getpitfall(int32_t x, int32_t y){return 0;}
26233
26234 bool update_hw_pal = false;
26235 void update_hw_screen()
26236 {
26237 if (is_headless())
26238 return;
26239
26240 framecnt++;
26241
26242 zc_process_display_events();
26243 if (update_hw_pal)
26244 {
26245 zc_set_palette(RAMpal);
26246 update_hw_pal = false;
26247 }
26248
26249 render_timer_wait();
26250 render_zq();
26251 }
26252
26253 bool checkCost(int32_t ctr, int32_t amnt)
26254 {
26255 if(!game) return true;
26256 if(amnt <= 0) return true;
26257 switch (ctr)
26258 {
26259 case crMONEY: //rupees
26260 {
26261 if ( current_item_power(itype_wallet) ) return true;
26262 break;
26263 }
26264 case crMAGIC: //magic
26265 {
26266 if (get_qr(qr_ENABLEMAGIC))
26267 {
26268 return (((current_item_power(itype_magicring) > 0)
26269 ? game->get_maxmagic()
26270 : game->get_magic()+game->get_dmagic())>=amnt*game->get_magicdrainrate());
26271 }
26272 return true;
26273 }
26274 case crARROWS:
26275 {
26276 if(current_item_power(itype_quiver))
26277 return true;
26278 if(!get_qr(qr_TRUEARROWS))
26279 return checkCost(crMONEY, amnt);
26280 break;
26281 }
26282 case crBOMBS:
26283 {
26284 if(current_item_power(itype_bombbag))
26285 return true;
26286 break;
26287 }
26288 case crSBOMBS:
26289 {
26290 if(current_item_power(itype_bombbag)
26291 && itemsbuf[current_item_id(itype_bombbag)].flags & item_flag1)
26292 return true;
26293 break;
26294 }
26295 }
26296 return (game->get_counter(ctr)+game->get_dcounter(ctr)>=amnt);
26297 }
26298 bool checkmagiccost(int32_t itemid, bool checkTime)
26299 {
26300 if(itemid < 0)
26301 {
26302 return false;
26303 }
26304 itemdata const& id = itemsbuf[itemid];
26305 return checkCost(id.cost_counter[0], id.cost_amount[0])
26306 && checkCost(id.cost_counter[1], id.cost_amount[1]);
26307 }
26308 bool checkbunny(int32_t itemid)
26309 {
26310 return true;
26311 }
26312
26313 void payCost(int32_t ctr, int32_t amnt, int32_t tmr, bool ignoreTimer)
26314 {
26315 return;
26316 }
26317 void paymagiccost(int32_t itemid, bool ignoreTimer, bool onlyTimer)
26318 {
26319 return;
26320 }
26321 bool is_in_scrolling_region()
26322 {
26323 return false;
26324 }
26325
26326 void enter_sys_pal(){}
26327 void exit_sys_pal(){}
26328
26329 void replay_step_comment(std::string comment) {}
26330 bool replay_is_active() {return false;}
26331 9 bool replay_is_replaying() {return false;}
26332 bool replay_version_check(int min, int max) {return max == -1;}
26333 bool replay_is_debug() {return false;}
26334 std::string replay_get_meta_str(std::string key){return "";}
26335 int32_t item::run_script(int32_t mode){return 0;};
26336 ffcdata* slopes_getFFC(int id)
26337 {
26338 return nullptr;
26339 }
26340
26341 int calculate_test_dmap()
26342 {
26343 int dmap = -1;
26344 auto pal = Map.getcolor();
26345 int scr = Map.getCurrScr();
26346 int scrx = scr & 0x0F;
26347 for(auto q = 0; q < MAXDMAPS; ++q)
26348 {
26349 auto& dm = DMaps[q];
26350 if(dm.map != Map.getCurrMap())
26351 continue;
26352 if((dm.type&dmfTYPE)!=dmOVERW)
26353 {
26354 if(scrx < dm.xoff || scrx >= dm.xoff+8)
26355 continue;
26356 }
26357 if(dmap < 0)
26358 dmap = q; // soft-accept this, but look for better still
26359 if(pal == dm.color)
26360 {
26361 dmap = q;
26362 // found the best match we have information for, break out
26363 break;
26364 }
26365 }
26366 if(dmap < 0) dmap = 0;
26367 return dmap;
26368 }
26369
26370 #ifdef __EMSCRIPTEN__
26371 extern "C" void open_test_mode()
26372 {
26373 int dmap = calculate_test_dmap();
26374 int scr = zc_min(0x7F, Map.getCurrScr());
26375
26376 em_open_test_mode(filepath, dmap, scr, -1);
26377 }
26378
26379 extern "C" void get_shareable_url()
26380 {
26381 EM_ASM({
26382 ZC.setShareableUrl({open: UTF8ToString($0), map: $1, screen: $2});
26383 }, filepath, Map.getCurrMap(), Map.getCurrScr());
26384 }
26385 #endif
26386
26387 11 void setZScriptVersion(int32_t v){}
26388
26389 static vector<string> wrap_qr_info(string info)
26390 {
26391 static const int max_chars = 140;
26392 info = info.substr(0, info.find_last_not_of(" \t\n")+1);
26393 if (info.empty())
26394 return {};
26395 if (auto ws_idx = info.find_first_not_of(" \t\n"); ws_idx != string::npos)
26396 info = info.substr(ws_idx);
26397 if (info.size() <= max_chars && info.find_first_of("\n") == string::npos)
26398 return { info };
26399 vector<string> ret;
26400
26401 size_t idx = 0;
26402 while (idx < info.size())
26403 {
26404 while (info[idx] == '\n')
26405 {
26406 ret.push_back("");
26407 ++idx;
26408 }
26409 idx = info.find_first_not_of(" ", idx); // skip leading ws
26410
26411 size_t newline_idx = info.find_first_of("\n", idx);
26412 size_t new_idx = idx + max_chars;
26413 if (newline_idx != string::npos)
26414 new_idx = zc_min(newline_idx, new_idx);
26415 if (new_idx < info.size())
26416 {
26417 for (int ptr = new_idx - idx; ptr >= 0; --ptr)
26418 {
26419 char c = info[idx+ptr];
26420 if (c == ' ' || c == '\n')
26421 break;
26422 if (ptr == max_chars) continue;
26423 new_idx = idx + ptr;
26424 }
26425 }
26426 string tmp = info.substr(idx, new_idx-idx);
26427 tmp = tmp.substr(0, tmp.find_last_not_of(" ")+1); // trim trailing ws
26428 ret.push_back(tmp);
26429 // if (info[new_idx] == "\n")
26430 // ++new_idx;
26431 idx = new_idx;
26432 }
26433 return ret;
26434 }
26435 void dev_output_qrs(string const& fname)
26436 {
26437 static std::map<int, string> qr_const_names = {
26438 { qr_SOLIDBLK, "qr_SOLIDBLK" },
26439 { qr_NOTMPNORET, "qr_NOTMPNORET" },
26440 { qr_ALWAYSRET, "qr_ALWAYSRET" },
26441 { qr_MEANTRAPS, "qr_MEANTRAPS" },
26442 { qr_BSZELDA, "qr_BSZELDA" },
26443 { qr_FADE, "qr_FADE" },
26444 { qr_FADECS5, "qr_FADECS5" },
26445 { qr_FASTDNGN, "qr_FASTDNGN" },
26446 { qr_NOLEVEL3FIX, "qr_NOLEVEL3FIX" },
26447 { qr_COOLSCROLL, "qr_COOLSCROLL" },
26448 { qr_NOSCROLL, "qr_NOSCROLL" },
26449 { qr_4TRI, "qr_4TRI" },
26450 { qr_EXPLICIT_RAFTING, "qr_EXPLICIT_RAFTING" },
26451 { qr_FASTFILL, "qr_FASTFILL" },
26452 { qr_CAVEEXITNOSTOPMUSIC, "qr_CAVEEXITNOSTOPMUSIC" },
26453 { qr_3TRI, "qr_3TRI" },
26454 { qr_TIME, "qr_TIME" },
26455 { qr_FREEFORM, "qr_FREEFORM" },
26456 { qr_KILLALL, "qr_KILLALL" },
26457 { qr_NOFLICKER, "qr_NOFLICKER" },
26458 { qr_CONTFULL_DEP, "qr_CONTFULL_DEP" },
26459 { qr_RLFIX, "qr_RLFIX" },
26460 { qr_LENSHINTS, "qr_LENSHINTS" },
26461 { qr_HERODUNGEONPOSFIX, "qr_HERODUNGEONPOSFIX" },
26462 { qr_HOLDITEMANIMATION, "qr_HOLDITEMANIMATION" },
26463 { qr_HESITANTPUSHBLOCKS, "qr_HESITANTPUSHBLOCKS" },
26464 { qr_HIDECARRIEDITEMS, "qr_HIDECARRIEDITEMS" },
26465 { qr_FFCSCROLL, "qr_FFCSCROLL" },
26466 { qr_RAFTLENS, "qr_RAFTLENS" },
26467 { qr_SMOOTHVERTICALSCROLLING, "qr_SMOOTHVERTICALSCROLLING" },
26468 { qr_WHIRLWINDMIRROR, "qr_WHIRLWINDMIRROR" },
26469 { qr_NOFLASHDEATH, "qr_NOFLASHDEATH" },
26470 { qr_HOLDNOSTOPMUSIC, "qr_HOLDNOSTOPMUSIC" },
26471 { qr_FIREPROOFHERO, "qr_FIREPROOFHERO" },
26472 { qr_OUCHBOMBS, "qr_OUCHBOMBS" },
26473 { qr_NOCLOCKS_DEP, "qr_NOCLOCKS_DEP" },
26474 { qr_TEMPCLOCKS_DEP, "qr_TEMPCLOCKS_DEP" },
26475 { qr_BRKBLSHLDS_DEP, "qr_BRKBLSHLDS_DEP" },
26476 { qr_BRKNSHLDTILES, "qr_BRKNSHLDTILES" },
26477 { qr_MEANPLACEDTRAPS, "qr_MEANPLACEDTRAPS" },
26478 { qr_PHANTOMPLACEDTRAPS, "qr_PHANTOMPLACEDTRAPS" },
26479 { qr_ALLOWFASTMSG, "qr_ALLOWFASTMSG" },
26480 { qr_LINKEDCOMBOS, "qr_LINKEDCOMBOS" },
26481 { qr_NOGUYFIRES, "qr_NOGUYFIRES" },
26482 { qr_HEARTRINGFIX, "qr_HEARTRINGFIX" },
26483 { qr_NOHEARTRING, "qr_NOHEARTRING" },
26484 { qr_OVERWORLDTUNIC, "qr_OVERWORLDTUNIC" },
26485 { qr_SWORDWANDFLIPFIX, "qr_SWORDWANDFLIPFIX" },
26486 { qr_ENABLEMAGIC, "qr_ENABLEMAGIC" },
26487 { qr_MAGICWAND_DEP, "qr_MAGICWAND_DEP" },
26488 { qr_MAGICCANDLE_DEP, "qr_MAGICCANDLE_DEP" },
26489 { qr_MAGICBOOTS_DEP, "qr_MAGICBOOTS_DEP" },
26490 { qr_NONBUBBLEMEDICINE, "qr_NONBUBBLEMEDICINE" },
26491 { qr_NONBUBBLEFAIRIES, "qr_NONBUBBLEFAIRIES" },
26492 { qr_NONBUBBLETRIFORCE, "qr_NONBUBBLETRIFORCE" },
26493 { qr_NEWENEMYTILES, "qr_NEWENEMYTILES" },
26494 { qr_NOROPE2FLASH_DEP, "qr_NOROPE2FLASH_DEP" },
26495 { qr_NOBUBBLEFLASH_DEP, "qr_NOBUBBLEFLASH_DEP" },
26496 { qr_GHINI2BLINK_DEP, "qr_GHINI2BLINK_DEP" },
26497 { qr_BITMAPOFFSETFIX, "qr_BITMAPOFFSETFIX" },
26498 { qr_PHANTOMGHINI2_DEP, "qr_PHANTOMGHINI2_DEP" },
26499 { qr_Z3BRANG_HSHOT, "qr_Z3BRANG_HSHOT" },
26500 { qr_NOITEMMELEE, "qr_NOITEMMELEE" },
26501 { qr_SHADOWS, "qr_SHADOWS" },
26502 { qr_TRANSSHADOWS, "qr_TRANSSHADOWS" },
26503 { qr_QUICKSWORD, "qr_QUICKSWORD" },
26504 { qr_BOMBHOLDFIX, "qr_BOMBHOLDFIX" },
26505 { qr_EXPANDEDLTM, "qr_EXPANDEDLTM" },
26506 { qr_NOPOTIONCOMBINE_DEP, "qr_NOPOTIONCOMBINE_DEP" },
26507 { qr_HEROFLICKER, "qr_HEROFLICKER" },
26508 { qr_SHADOWSFLICKER, "qr_SHADOWSFLICKER" },
26509 { qr_WALLFLIERS, "qr_WALLFLIERS" },
26510 { qr_NOBOMBPALFLASH, "qr_NOBOMBPALFLASH" },
26511 { qr_HEARTSREQUIREDFIX, "qr_HEARTSREQUIREDFIX" },
26512 { qr_PUSHBLOCKCSETFIX, "qr_PUSHBLOCKCSETFIX" },
26513 { qr_TRANSLUCENTDIVINEPROTECTIONROCKET_DEP, "qr_TRANSLUCENTDIVINEPROTECTIONROCKET_DEP" },
26514 { qr_FLICKERINGDIVINEPROTECTIONROCKET_DEP, "qr_FLICKERINGDIVINEPROTECTIONROCKET_DEP" },
26515 { qr_CMBCYCLELAYERS, "qr_CMBCYCLELAYERS" },
26516 { qr_DMGCOMBOPRI, "qr_DMGCOMBOPRI" },
26517 { qr_WARPSIGNOREARRIVALPOINT, "qr_WARPSIGNOREARRIVALPOINT" },
26518 { qr_LTTPCOLLISION, "qr_LTTPCOLLISION" },
26519 { qr_LTTPWALK, "qr_LTTPWALK" },
26520 { qr_SLOWENEMYANIM_DEP, "qr_SLOWENEMYANIM_DEP" },
26521 { qr_TRUEARROWS, "qr_TRUEARROWS" },
26522 { qr_NOSAVE, "qr_NOSAVE" },
26523 { qr_NOCONTINUE, "qr_NOCONTINUE" },
26524 { qr_QUARTERHEART, "qr_QUARTERHEART" },
26525 { qr_NOARRIVALPOINT, "qr_NOARRIVALPOINT" },
26526 { qr_NOGUYPOOF, "qr_NOGUYPOOF" },
26527 { qr_ALLOWMSGBYPASS, "qr_ALLOWMSGBYPASS" },
26528 { qr_NODIVING, "qr_NODIVING" },
26529 { qr_LAYER12UNDERCAVE, "qr_LAYER12UNDERCAVE" },
26530 { qr_NOSCROLLCONTINUE, "qr_NOSCROLLCONTINUE" },
26531 { qr_SMARTSCREENSCROLL, "qr_SMARTSCREENSCROLL" },
26532 { qr_RINGAFFECTDAMAGE, "qr_RINGAFFECTDAMAGE" },
26533 { qr_ALLOW10RUPEEDROPS_DEP, "qr_ALLOW10RUPEEDROPS_DEP" },
26534 { qr_TRAPPOSFIX, "qr_TRAPPOSFIX" },
26535 { qr_TEMPCANDLELIGHT, "qr_TEMPCANDLELIGHT" },
26536 { qr_REDPOTIONONCE_DEP, "qr_REDPOTIONONCE_DEP" },
26537 { qr_OLDSTYLEWARP, "qr_OLDSTYLEWARP" },
26538 { qr_NOBORDER, "qr_NOBORDER" },
26539 { qr_OLDTRIBBLES_DEP, "qr_OLDTRIBBLES_DEP" },
26540 { qr_REFLECTROCKS, "qr_REFLECTROCKS" },
26541 { qr_OLDPICKUP, "qr_OLDPICKUP" },
26542 { qr_ENEMIESZAXIS, "qr_ENEMIESZAXIS" },
26543 { qr_SAFEENEMYFADE, "qr_SAFEENEMYFADE" },
26544 { qr_MORESOUNDS, "qr_MORESOUNDS" },
26545 { qr_BRANGPICKUP, "qr_BRANGPICKUP" },
26546 { qr_HEARTPIECEINCR_DEP, "qr_HEARTPIECEINCR_DEP" },
26547 { qr_ITEMSONEDGES, "qr_ITEMSONEDGES" },
26548 { qr_EATSMALLSHIELD_DEP, "qr_EATSMALLSHIELD_DEP" },
26549 { qr_MSGFREEZE, "qr_MSGFREEZE" },
26550 { qr_SLASHFLIPFIX, "qr_SLASHFLIPFIX" },
26551 { qr_FIREMAGICSPRITE_DEP, "qr_FIREMAGICSPRITE_DEP" },
26552 { qr_SLOWCHARGINGWALK, "qr_SLOWCHARGINGWALK" },
26553 { qr_NOWANDMELEE, "qr_NOWANDMELEE" },
26554 { qr_SLOWBOMBFUSES_DEP, "qr_SLOWBOMBFUSES_DEP" },
26555 { qr_SWORDMIRROR, "qr_SWORDMIRROR" },
26556 { qr_SELECTAWPN, "qr_SELECTAWPN" },
26557 { qr_LENSSEESENEMIES, "qr_LENSSEESENEMIES" },
26558 { qr_INSTABURNFLAGS, "qr_INSTABURNFLAGS" },
26559 { qr_DROWN, "qr_DROWN" },
26560 { qr_MSGDISAPPEAR, "qr_MSGDISAPPEAR" },
26561 { qr_SUBSCREENOVERSPRITES, "qr_SUBSCREENOVERSPRITES" },
26562 { qr_BOMBDARKNUTFIX, "qr_BOMBDARKNUTFIX" },
26563 { qr_LONGBOMBBOOM_DEP, "qr_LONGBOMBBOOM_DEP" },
26564 { qr_OFFSETEWPNCOLLISIONFIX, "qr_OFFSETEWPNCOLLISIONFIX" },
26565 { qr_DMGCOMBOLAYERFIX, "qr_DMGCOMBOLAYERFIX" },
26566 { qr_ITEMSINPASSAGEWAYS, "qr_ITEMSINPASSAGEWAYS" },
26567 { qr_LOG, "qr_LOG" },
26568 { qr_FIREPROOFHERO2, "qr_FIREPROOFHERO2" },
26569 { qr_NOITEMOFFSET, "qr_NOITEMOFFSET" },
26570 { qr_ITEMBUBBLE, "qr_ITEMBUBBLE" },
26571 { qr_GOTOLESSNOTEQUAL, "qr_GOTOLESSNOTEQUAL" },
26572 { qr_LADDERANYWHERE, "qr_LADDERANYWHERE" },
26573 { qr_HOOKSHOTLAYERFIX, "qr_HOOKSHOTLAYERFIX" },
26574 { qr_REPLACEOPENDOORS, "qr_REPLACEOPENDOORS" },
26575 { qr_OLDLENSORDER, "qr_OLDLENSORDER" },
26576 { qr_NOFAIRYGUYFIRES, "qr_NOFAIRYGUYFIRES" },
26577 { qr_SCRIPTERRLOG, "qr_SCRIPTERRLOG" },
26578 { qr_TRIGGERSREPEAT, "qr_TRIGGERSREPEAT" },
26579 { qr_ENEMIESFLICKER, "qr_ENEMIESFLICKER" },
26580 { qr_OVALWIPE, "qr_OVALWIPE" },
26581 { qr_TRIANGLEWIPE, "qr_TRIANGLEWIPE" },
26582 { qr_SMASWIPE, "qr_SMASWIPE" },
26583 { qr_NOSOLIDDAMAGECOMBOS, "qr_NOSOLIDDAMAGECOMBOS" },
26584 { qr_SHOPCHEAT, "qr_SHOPCHEAT" },
26585 { qr_HOOKSHOTDOWNBUG, "qr_HOOKSHOTDOWNBUG" },
26586 { qr_OLDHOOKSHOTGRAB, "qr_OLDHOOKSHOTGRAB" },
26587 { qr_PEAHATCLOCKVULN, "qr_PEAHATCLOCKVULN" },
26588 { qr_VERYFASTSCROLLING, "qr_VERYFASTSCROLLING" },
26589 { qr_OFFSCREENWEAPONS, "qr_OFFSCREENWEAPONS" },
26590 { qr_BROKENSTATUES, "qr_BROKENSTATUES" },
26591 { qr_BOMBCHUSUPERBOMB, "qr_BOMBCHUSUPERBOMB" },
26592 { qr_ITEMPICKUPSETSBELOW, "qr_ITEMPICKUPSETSBELOW" },
26593 { qr_GANONINTRO, "qr_GANONINTRO" },
26594 { qr_MELEEMAGICCOST, "qr_MELEEMAGICCOST" },
26595 { qr_OLDMIRRORCOMBOS, "qr_OLDMIRRORCOMBOS" },
26596 { qr_BROKENBOOKCOST, "qr_BROKENBOOKCOST" },
26597 { qr_OLDSIDEVIEWSPIKES, "qr_OLDSIDEVIEWSPIKES" },
26598 { qr_OLDINFMAGIC, "qr_OLDINFMAGIC" },
26599 { qr_NEVERDISABLEAMMOONSUBSCREEN, "qr_NEVERDISABLEAMMOONSUBSCREEN" },
26600 { qr_ITEMSCRIPTSKEEPRUNNING, "qr_ITEMSCRIPTSKEEPRUNNING" },
26601 { qr_SCRIPTSRUNINHEROSTEPFORWARD, "qr_SCRIPTSRUNINHEROSTEPFORWARD" },
26602 { qr_FIXSCRIPTSDURINGSCROLLING, "qr_FIXSCRIPTSDURINGSCROLLING" },
26603 { qr_SCRIPTDRAWSINWARPS, "qr_SCRIPTDRAWSINWARPS" },
26604 { qr_DYINGENEMYESDONTHURTHERO, "qr_DYINGENEMYESDONTHURTHERO" },
26605 { qr_SIDEVIEWTRIFORCECELLAR, "qr_SIDEVIEWTRIFORCECELLAR" },
26606 { qr_OUTOFBOUNDSENEMIES, "qr_OUTOFBOUNDSENEMIES" },
26607 { qr_EPILEPSY, "qr_EPILEPSY" },
26608 { qr_SCRIPT_FRIENDLY_ENEMY_TYPES, "qr_SCRIPT_FRIENDLY_ENEMY_TYPES" },
26609 { qr_SMARTDROPS, "qr_SMARTDROPS" },
26610 { qr_NO_L_R_BUTTON_INVENTORY_SWAP, "qr_NO_L_R_BUTTON_INVENTORY_SWAP" },
26611 { qr_USE_EX1_EX2_INVENTORYSWAP, "qr_USE_EX1_EX2_INVENTORYSWAP" },
26612 { qr_NOFASTMODE, "qr_NOFASTMODE" },
26613 { qr_OLD_F6, "qr_OLD_F6" },
26614 { qr_BROKEN_ASKIP_Y_FRAMES, "qr_BROKEN_ASKIP_Y_FRAMES" },
26615 { qr_ENEMY_BROKEN_TOP_HALF_SOLIDITY, "qr_ENEMY_BROKEN_TOP_HALF_SOLIDITY" },
26616 { qr_SIDEVIEWLADDER_FACEUP, "qr_SIDEVIEWLADDER_FACEUP" },
26617 { qr_ITEMS_IGNORE_SIDEVIEW_PLATFORMS, "qr_ITEMS_IGNORE_SIDEVIEW_PLATFORMS" },
26618 { qr_DOWN_FALL_THROUGH_SIDEVIEW_PLATFORMS, "qr_DOWN_FALL_THROUGH_SIDEVIEW_PLATFORMS" },
26619 { qr_SIDEVIEW_FALLTHROUGH_USES_DRUNK, "qr_SIDEVIEW_FALLTHROUGH_USES_DRUNK" },
26620 { qr_DOWN_DOESNT_GRAB_LADDERS, "qr_DOWN_DOESNT_GRAB_LADDERS" },
26621 { qr_DOWNJUMP_FALL_THROUGH_SIDEVIEW_PLATFORMS, "qr_DOWNJUMP_FALL_THROUGH_SIDEVIEW_PLATFORMS" },
26622 { qr_OLD_SIDEVIEW_CEILING_COLLISON, "qr_OLD_SIDEVIEW_CEILING_COLLISON" },
26623 { qr_0AFRAME_ITEMS_IGNORE_AFRAME_CHANGES, "qr_0AFRAME_ITEMS_IGNORE_AFRAME_CHANGES" },
26624 { qr_OLD_ENEMY_KNOCKBACK_COLLISION, "qr_OLD_ENEMY_KNOCKBACK_COLLISION" },
26625 { qr_FADEBLACKWIPE, "qr_FADEBLACKWIPE" },
26626 { qr_PASSIVE_SUBSCRIPT_RUNS_DURING_ACTIVE_SUBSCRIPT, "qr_PASSIVE_SUBSCRIPT_RUNS_DURING_ACTIVE_SUBSCRIPT" },
26627 { qr_DMAP_ACTIVE_RUNS_DURING_ACTIVE_SUBSCRIPT, "qr_DMAP_ACTIVE_RUNS_DURING_ACTIVE_SUBSCRIPT" },
26628 { qr_ANIMATECUSTOMWEAPONS, "qr_ANIMATECUSTOMWEAPONS" },
26629 { qr_WEAPONSMOVEOFFSCREEN, "qr_WEAPONSMOVEOFFSCREEN" },
26630 { qr_CHECKSCRIPTWEAPONOFFSCREENCLIP, "qr_CHECKSCRIPTWEAPONOFFSCREENCLIP" },
26631 { qr_SHORTDGNWALK, "qr_SHORTDGNWALK" },
26632 { qr_SCRIPT_WEAPONS_UNIQUE_SPRITES, "qr_SCRIPT_WEAPONS_UNIQUE_SPRITES" },
26633 { qr_ANGULAR_REFLECTED_WEAPONS, "qr_ANGULAR_REFLECTED_WEAPONS" },
26634 { qr_MIRRORS_USE_WEAPON_CENTER, "qr_MIRRORS_USE_WEAPON_CENTER" },
26635 { qr_CUSTOMCOMBOSLAYERS1AND2, "qr_CUSTOMCOMBOSLAYERS1AND2" },
26636 { qr_BUSHESONLAYERS1AND2, "qr_BUSHESONLAYERS1AND2" },
26637 { qr_NEW_HERO_MOVEMENT, "qr_NEW_HERO_MOVEMENT" },
26638 { qr_DISABLE_4WAY_GRIDLOCK, "qr_DISABLE_4WAY_GRIDLOCK" },
26639 { qr_NEW_COMBO_ANIMATION, "qr_NEW_COMBO_ANIMATION" },
26640 { qr_OLD_STRING_EDITOR_MARGINS, "qr_OLD_STRING_EDITOR_MARGINS" },
26641 { qr_NO_OVERWRITING_HOPPING, "qr_NO_OVERWRITING_HOPPING" },
26642 { qr_DUNGEON_DMAPS_PERM_SECRETS, "qr_DUNGEON_DMAPS_PERM_SECRETS" },
26643 { qr_STRING_FRAME_OLD_WIDTH_HEIGHT, "qr_STRING_FRAME_OLD_WIDTH_HEIGHT" },
26644 { qr_NO_SCROLL_WHILE_IN_AIR, "qr_NO_SCROLL_WHILE_IN_AIR" },
26645 { qr_INSTANT_RESPAWN, "qr_INSTANT_RESPAWN" },
26646 { qr_BROKEN_OVERWORLD_MINIMAP, "qr_BROKEN_OVERWORLD_MINIMAP" },
26647 { qr_NO_STUNLOCK_BLOCK, "qr_NO_STUNLOCK_BLOCK" },
26648 { qr_GREATER_MAX_TIME, "qr_GREATER_MAX_TIME" },
26649 { qr_BROKEN_RING_POWER, "qr_BROKEN_RING_POWER" },
26650 { qr_NO_OVERWORLD_MAP_CHARTING, "qr_NO_OVERWORLD_MAP_CHARTING" },
26651 { qr_DUNGEONS_USE_CLASSIC_CHARTING, "qr_DUNGEONS_USE_CLASSIC_CHARTING" },
26652 { qr_ARROWS_ALWAYS_PENETRATE, "qr_ARROWS_ALWAYS_PENETRATE" },
26653 { qr_SWORDBEAMS_ALWAYS_PENETRATE, "qr_SWORDBEAMS_ALWAYS_PENETRATE" },
26654 { qr_SET_XBUTTON_ITEMS, "qr_SET_XBUTTON_ITEMS" },
26655 { qr_SMARTER_WATER, "qr_SMARTER_WATER" },
26656 { qr_NO_HOPPING, "qr_NO_HOPPING" },
26657 { qr_NO_SOLID_SWIM, "qr_NO_SOLID_SWIM" },
26658 { qr_WATER_ON_LAYER_1, "qr_WATER_ON_LAYER_1" },
26659 { qr_WATER_ON_LAYER_2, "qr_WATER_ON_LAYER_2" },
26660 { qr_SHALLOW_SENSITIVE, "qr_SHALLOW_SENSITIVE" },
26661 { qr_SMARTER_SMART_SCROLL, "qr_SMARTER_SMART_SCROLL" },
26662 { qr_INSTANT_CONTINUE, "qr_INSTANT_CONTINUE" },
26663 { qr_NONHEAVY_BLOCKTRIGGER_PERM, "qr_NONHEAVY_BLOCKTRIGGER_PERM" },
26664 { qr_SET_YBUTTON_ITEMS, "qr_SET_YBUTTON_ITEMS" },
26665 { qr_CORRECTED_EW_BRANG_ANIM, "qr_CORRECTED_EW_BRANG_ANIM" },
26666 { qr_SCRIPT_WRITING_HEROSTEP_DOESNT_CARRY_OVER, "qr_SCRIPT_WRITING_HEROSTEP_DOESNT_CARRY_OVER" },
26667 { qr_OVERHEAD_COMBOS_L1_L2, "qr_OVERHEAD_COMBOS_L1_L2" },
26668 { qr_ALLOW_EDITING_COMBO_0, "qr_ALLOW_EDITING_COMBO_0" },
26669 { qr_OLD_CHEST_COLLISION, "qr_OLD_CHEST_COLLISION" },
26670 { qr_AUTOCOMBO_LAYER_1, "qr_AUTOCOMBO_LAYER_1" },
26671 { qr_AUTOCOMBO_LAYER_2, "qr_AUTOCOMBO_LAYER_2" },
26672 { qr_TRUEFIXEDBOMBSHIELD, "qr_TRUEFIXEDBOMBSHIELD" },
26673 { qr_BOMBSPIERCESHIELD, "qr_BOMBSPIERCESHIELD" },
26674 { qr_BROKEN_HORIZONTAL_WEAPON_ANIM, "qr_BROKEN_HORIZONTAL_WEAPON_ANIM" },
26675 { qr_NEW_DARKROOM, "qr_NEW_DARKROOM" },
26676 { qr_NEWDARK_L6, "qr_NEWDARK_L6" },
26677 { qr_ENEMIES_SECRET_ONLY_16_31, "qr_ENEMIES_SECRET_ONLY_16_31" },
26678 { qr_SCREEN80_OWN_MUSIC, "qr_SCREEN80_OWN_MUSIC" },
26679 { qr_OLDCS2, "qr_OLDCS2" },
26680 { qr_HARDCODED_ENEMY_ANIMS, "qr_HARDCODED_ENEMY_ANIMS" },
26681 { qr_OLD_ITEMDATA_SCRIPT_TIMING, "qr_OLD_ITEMDATA_SCRIPT_TIMING" },
26682 { qr_SIDESWIM, "qr_SIDESWIM" },
26683 { qr_SIDESWIMDIR, "qr_SIDESWIMDIR" },
26684 { qr_PUSHBLOCK_LAYER_1_2, "qr_PUSHBLOCK_LAYER_1_2" },
26685 { qr_NEWDARK_SCROLLEDGE, "qr_NEWDARK_SCROLLEDGE" },
26686 { qr_STEPTEMP_SECRET_ONLY_16_31, "qr_STEPTEMP_SECRET_ONLY_16_31" },
26687 { qr_ALLTRIG_PERMSEC_NO_TEMP, "qr_ALLTRIG_PERMSEC_NO_TEMP" },
26688 { qr_HARDCODED_LITEM_LTMS, "qr_HARDCODED_LITEM_LTMS" },
26689 { qr_NO_BOTTLE_IF_ANY_COUNTER_FULL, "qr_NO_BOTTLE_IF_ANY_COUNTER_FULL" },
26690 { qr_LIGHTBEAM_TRANSPARENT, "qr_LIGHTBEAM_TRANSPARENT" },
26691 { qr_CANDLES_SHARED_LIMIT, "qr_CANDLES_SHARED_LIMIT" },
26692 { qr_OLD_RESPAWN_POINTS, "qr_OLD_RESPAWN_POINTS" },
26693 { qr_HOOKSHOTALLLAYER, "qr_HOOKSHOTALLLAYER" },
26694 { qr_ANONE_NOANIM, "qr_ANONE_NOANIM" },
26695 { qr_BLOCKHOLE_SAME_ONLY, "qr_BLOCKHOLE_SAME_ONLY" },
26696 { qr_SWITCHOBJ_RUN_SCRIPT, "qr_SWITCHOBJ_RUN_SCRIPT" },
26697 { qr_ITEMCOMBINE_NEW_PSTR, "qr_ITEMCOMBINE_NEW_PSTR" },
26698 { qr_ITEMCOMBINE_CONTINUOUS, "qr_ITEMCOMBINE_CONTINUOUS" },
26699 { qr_SCC_ITEM_COMBINES_ITEMS, "qr_SCC_ITEM_COMBINES_ITEMS" },
26700 { qr_SCROLLING_KILLS_CHARGE, "qr_SCROLLING_KILLS_CHARGE" },
26701 { qr_CUSTOMWEAPON_IGNORE_COST, "qr_CUSTOMWEAPON_IGNORE_COST" },
26702 { qr_BLOCKS_DONT_LOCK_OTHER_LAYERS, "qr_BLOCKS_DONT_LOCK_OTHER_LAYERS" },
26703 { qr_SCC_GOTO_RESPECTS_CONTFLAG, "qr_SCC_GOTO_RESPECTS_CONTFLAG" },
26704 { qr_BROKEN_KEEPOLD_FLAG, "qr_BROKEN_KEEPOLD_FLAG" },
26705 { qr_KEEPOLD_APPLIES_RETROACTIVELY, "qr_KEEPOLD_APPLIES_RETROACTIVELY" },
26706 { qr_PASSIVE_ITEM_SCRIPT_ONLY_HIGHEST, "qr_PASSIVE_ITEM_SCRIPT_ONLY_HIGHEST" },
26707 { qr_OLD_HALF_MAGIC, "qr_OLD_HALF_MAGIC" },
26708 { qr_LEVEL_RESTART_CONT_POINT, "qr_LEVEL_RESTART_CONT_POINT" },
26709 { qr_SUBSCR_OLD_SELECTOR, "qr_SUBSCR_OLD_SELECTOR" },
26710 { qr_OLD_FAIRY_LIMIT, "qr_OLD_FAIRY_LIMIT" },
26711 { qr_FAIRYDIR, "qr_FAIRYDIR" },
26712 { qr_ARROWCLIP, "qr_ARROWCLIP" },
26713 { qr_CONT_SWORD_TRIGGERS, "qr_CONT_SWORD_TRIGGERS" },
26714 { qr_OLD_210_WATER, "qr_OLD_210_WATER" },
26715 { qr_8WAY_SHOT_SFX_DEP, "qr_8WAY_SHOT_SFX_DEP" },
26716 { qr_COPIED_SWIM_SPRITES, "qr_COPIED_SWIM_SPRITES" },
26717 { qr_WRONG_BRANG_TRAIL_DIR, "qr_WRONG_BRANG_TRAIL_DIR" },
26718 { qr_192b163_WARP, "qr_192b163_WARP" },
26719 { qr_210_WARPRETURN, "qr_210_WARPRETURN" },
26720 { qr_LESS_AWFUL_SIDESPIKES, "qr_LESS_AWFUL_SIDESPIKES" },
26721 { qr_OLD_LADDER_ITEM_SIDEVIEW, "qr_OLD_LADDER_ITEM_SIDEVIEW" },
26722 { qr_OLD_SECRETMONEY, "qr_OLD_SECRETMONEY" },
26723 { qr_OLD_DOORREPAIR, "qr_OLD_DOORREPAIR" },
26724 { qr_OLD_POTION_OR_HC, "qr_OLD_POTION_OR_HC" },
26725 { qr_NO_LANMOLA_RINGLEADER, "qr_NO_LANMOLA_RINGLEADER" },
26726 { qr_HARDCODED_BS_PATRA, "qr_HARDCODED_BS_PATRA" },
26727 { qr_PATRAS_USE_HARDCODED_OFFSETS, "qr_PATRAS_USE_HARDCODED_OFFSETS" },
26728 { qr_BROKEN_BIG_ENEMY_ANIMATION, "qr_BROKEN_BIG_ENEMY_ANIMATION" },
26729 { qr_BROKEN_ATTRIBUTE_31_32, "qr_BROKEN_ATTRIBUTE_31_32" },
26730 { qr_CAN_PLACE_GANON, "qr_CAN_PLACE_GANON" },
26731 { qr_CAN_PLACE_TRAPS, "qr_CAN_PLACE_TRAPS" },
26732 { qr_FIND_CLOSEST_BAIT, "qr_FIND_CLOSEST_BAIT" },
26733 { qr_OLD_FLAMETRAIL_DURATION, "qr_OLD_FLAMETRAIL_DURATION" },
26734 { qr_PERMANENT_WHISTLE_SECRETS, "qr_PERMANENT_WHISTLE_SECRETS" },
26735 { qr_SMARTER_DROPS, "qr_SMARTER_DROPS" },
26736 { qr_WAVY_NO_EPILEPSY, "qr_WAVY_NO_EPILEPSY" },
26737 { qr_WAVY_NO_EPILEPSY_2, "qr_WAVY_NO_EPILEPSY_2" },
26738 { qr_DYING_ENEMIES_IGNORE_STUN, "qr_DYING_ENEMIES_IGNORE_STUN" },
26739 { qr_SHOP_ITEMS_VANISH, "qr_SHOP_ITEMS_VANISH" },
26740 { qr_ANGULAR_REFLECT_BROKEN, "qr_ANGULAR_REFLECT_BROKEN" },
26741 { qr_CSET1_LEVEL, "qr_CSET1_LEVEL" },
26742 { qr_CSET5_LEVEL, "qr_CSET5_LEVEL" },
26743 { qr_CSET7_LEVEL, "qr_CSET7_LEVEL" },
26744 { qr_CSET8_LEVEL, "qr_CSET8_LEVEL" },
26745 { qr_FADECS1, "qr_FADECS1" },
26746 { qr_FADECS7, "qr_FADECS7" },
26747 { qr_FADECS8, "qr_FADECS8" },
26748 { qr_FADECS9, "qr_FADECS9" },
26749 { qr_UNBEATABLES_DONT_KEEP_DEAD, "qr_UNBEATABLES_DONT_KEEP_DEAD" },
26750 { qr_NO_LEAVE_ONE_ENEMY_ALIVE_TRICK, "qr_NO_LEAVE_ONE_ENEMY_ALIVE_TRICK" },
26751 { qr_OLD_BRIDGE_COMBOS, "qr_OLD_BRIDGE_COMBOS" },
26752 { qr_BROKEN_Z3_ANIMATION, "qr_BROKEN_Z3_ANIMATION" },
26753 { qr_OLD_TILE_INITIALIZATION, "qr_OLD_TILE_INITIALIZATION" },
26754 { qr_FLUCTUATING_ENEMY_JUMP, "qr_FLUCTUATING_ENEMY_JUMP" },
26755 { qr_SPRITE_JUMP_IS_TRUNCATED, "qr_SPRITE_JUMP_IS_TRUNCATED" },
26756 { qr_BUGGY_BUGGY_SLASH_TRIGGERS, "qr_BUGGY_BUGGY_SLASH_TRIGGERS" },
26757 { qr_OLD_DRAWOFFSET, "qr_OLD_DRAWOFFSET" },
26758 { qr_BROKEN_DRAWSCREEN_FUNCTIONS, "qr_BROKEN_DRAWSCREEN_FUNCTIONS" },
26759 { qr_ENEMY_DROPS_USE_HITOFFSETS, "qr_ENEMY_DROPS_USE_HITOFFSETS" },
26760 { qr_BROKEN_ITEM_CARRYING, "qr_BROKEN_ITEM_CARRYING" },
26761 { qr_LEEVERS_DONT_OBEY_STUN, "qr_LEEVERS_DONT_OBEY_STUN" },
26762 { qr_QUAKE_STUNS_LEEVERS, "qr_QUAKE_STUNS_LEEVERS" },
26763 { qr_GANON_CANT_SPAWN_ON_CONTINUE, "qr_GANON_CANT_SPAWN_ON_CONTINUE" },
26764 { qr_WIZZROBES_DONT_OBEY_STUN, "qr_WIZZROBES_DONT_OBEY_STUN" },
26765 { qr_OLD_BUG_NET, "qr_OLD_BUG_NET" },
26766 { qr_MANHANDLA_BLOCK_SFX, "qr_MANHANDLA_BLOCK_SFX" },
26767 { qr_GRASS_SENSITIVE, "qr_GRASS_SENSITIVE" },
26768 { qr_BETTER_RAFT, "qr_BETTER_RAFT" },
26769 { qr_BETTER_RAFT_2, "qr_BETTER_RAFT_2" },
26770 { qr_RAFT_SOUND, "qr_RAFT_SOUND" },
26771 { qr_WARPS_RESTART_DMAPSCRIPT, "qr_WARPS_RESTART_DMAPSCRIPT" },
26772 { qr_DMAP_0_CONTINUE_BUG, "qr_DMAP_0_CONTINUE_BUG" },
26773 { qr_SCRIPT_WARPS_DMAP_SCRIPT_TOGGLE, "qr_SCRIPT_WARPS_DMAP_SCRIPT_TOGGLE" },
26774 { qr_OLD_SCRIPTED_KNOCKBACK, "qr_OLD_SCRIPTED_KNOCKBACK" },
26775 { qr_OLD_KEESE_Z_AXIS, "qr_OLD_KEESE_Z_AXIS" },
26776 { qr_POLVIRE_NO_SHADOW, "qr_POLVIRE_NO_SHADOW" },
26777 { qr_CONVEYORS_L1_L2, "qr_CONVEYORS_L1_L2" },
26778 { qr_CUSTOMCOMBOS_EVERY_LAYER, "qr_CUSTOMCOMBOS_EVERY_LAYER" },
26779 { qr_SUBSCR_BACKWARDS_ID_ORDER, "qr_SUBSCR_BACKWARDS_ID_ORDER" },
26780 { qr_FASTCOUNTERDRAIN, "qr_FASTCOUNTERDRAIN" },
26781 { qr_OLD_LOCKBLOCK_COLLISION, "qr_OLD_LOCKBLOCK_COLLISION" },
26782 { qr_DECO_2_YOFFSET, "qr_DECO_2_YOFFSET" },
26783 { qr_SCREENSTATE_80s_BUG, "qr_SCREENSTATE_80s_BUG" },
26784 { qr_AUTOCOMBO_ANY_LAYER, "qr_AUTOCOMBO_ANY_LAYER" },
26785 { qr_GOHMA_UNDAMAGED_BUG, "qr_GOHMA_UNDAMAGED_BUG" },
26786 { qr_FFCPRELOAD_BUGGED_LOAD, "qr_FFCPRELOAD_BUGGED_LOAD" },
26787 { qr_SWITCHES_AFFECT_MOVINGBLOCKS, "qr_SWITCHES_AFFECT_MOVINGBLOCKS" },
26788 { qr_BROKEN_GETPIXEL_VALUE, "qr_BROKEN_GETPIXEL_VALUE" },
26789 { qr_NO_LIFT_SPRITE, "qr_NO_LIFT_SPRITE" },
26790 { qr_OLD_SIDEVIEW_LANDING_CODE, "qr_OLD_SIDEVIEW_LANDING_CODE" },
26791 { qr_OLD_FFC_SPEED_CAP, "qr_OLD_FFC_SPEED_CAP" },
26792 { qr_OLD_WIZZROBE_SUBMERGING, "qr_OLD_WIZZROBE_SUBMERGING" },
26793 { qr_SPARKLES_INHERIT_PROPERTIES, "qr_SPARKLES_INHERIT_PROPERTIES" },
26794 { qr_BROKENHITBY, "qr_BROKENHITBY" },
26795 { qr_ENEMIES_DONT_SCRIPT_FIRST_FRAME, "qr_ENEMIES_DONT_SCRIPT_FIRST_FRAME" },
26796 { qr_OLD_CONVEYOR_COLLISION, "qr_OLD_CONVEYOR_COLLISION" },
26797 { qr_SENSITIVE_SOLID_DAMAGE, "qr_SENSITIVE_SOLID_DAMAGE" },
26798 { qr_LENIENT_SOLID_DAMAGE, "qr_LENIENT_SOLID_DAMAGE" },
26799 { qr_NO_SIDEVIEW_SOLID_DAMAGE, "qr_NO_SIDEVIEW_SOLID_DAMAGE" },
26800 { qr_OLD_FFC_FUNCTIONALITY, "qr_OLD_FFC_FUNCTIONALITY" },
26801 { qr_OLD_SHALLOW_SFX, "qr_OLD_SHALLOW_SFX" },
26802 { qr_BUGGED_LAYERED_FLAGS, "qr_BUGGED_LAYERED_FLAGS" },
26803 { qr_HARDCODED_FFC_BUSH_DROPS, "qr_HARDCODED_FFC_BUSH_DROPS" },
26804 { qr_POUNDLAYERS1AND2, "qr_POUNDLAYERS1AND2" },
26805 { qr_MOVINGBLOCK_FAKE_SOLID, "qr_MOVINGBLOCK_FAKE_SOLID" },
26806 { qr_NEW_HERO_MOVEMENT2, "qr_NEW_HERO_MOVEMENT2" },
26807 { qr_CARRYABLE_NO_ACROSS_SCREEN, "qr_CARRYABLE_NO_ACROSS_SCREEN" },
26808 { qr_NO_SCROLL_WHILE_CARRYING, "qr_NO_SCROLL_WHILE_CARRYING" },
26809 { qr_HELD_BOMBS_EXPLODE, "qr_HELD_BOMBS_EXPLODE" },
26810 { qr_BROKEN_MOVING_BOMBS, "qr_BROKEN_MOVING_BOMBS" },
26811 { qr_OLD_BOMB_HITBOXES, "qr_OLD_BOMB_HITBOXES" },
26812 { qr_SCROLLWARP_NO_RESET_FRAME, "qr_SCROLLWARP_NO_RESET_FRAME" },
26813 { qr_BROKEN_RAFT_SCROLL, "qr_BROKEN_RAFT_SCROLL" },
26814 { qr_BROKEN_INPUT_DOWN_STATE, "qr_BROKEN_INPUT_DOWN_STATE" },
26815 { qr_OLD_GUY_HANDLING, "qr_OLD_GUY_HANDLING" },
26816 { qr_FREEFORM_SUBSCREEN_CURSOR, "qr_FREEFORM_SUBSCREEN_CURSOR" },
26817 { qr_SUBSCR_PRESS_TO_EQUIP, "qr_SUBSCR_PRESS_TO_EQUIP" },
26818 { qr_FAIRY_FLAG_COMPAT, "qr_FAIRY_FLAG_COMPAT" },
26819 { qr_MIRROR_PRISM_LAYERS, "qr_MIRROR_PRISM_LAYERS" },
26820 { qr_OLD_LENS_LAYEREFFECT, "qr_OLD_LENS_LAYEREFFECT" },
26821 { qr_PUSHBLOCK_SPRITE_LAYER, "qr_PUSHBLOCK_SPRITE_LAYER" },
26822 { qr_OLD_SUBSCR, "qr_OLD_SUBSCR" },
26823 { qr_ITM_0_INVIS_ON_BTNS, "qr_ITM_0_INVIS_ON_BTNS" },
26824 { qr_NO_BUTTON_VERIFY, "qr_NO_BUTTON_VERIFY" },
26825 { qr_OLD_GAUGE_TILE_LAYOUT, "qr_OLD_GAUGE_TILE_LAYOUT" },
26826 { qr_WALKTHROUGHWALL_NO_DOORSTATE, "qr_WALKTHROUGHWALL_NO_DOORSTATE" },
26827 { qr_SPOTLIGHT_IGNR_SOLIDOBJ, "qr_SPOTLIGHT_IGNR_SOLIDOBJ" },
26828 { qr_BROKEN_LIGHTBEAM_HITBOX, "qr_BROKEN_LIGHTBEAM_HITBOX" },
26829 { qr_BROKEN_SWORD_SPIN_TRIGGERS, "qr_BROKEN_SWORD_SPIN_TRIGGERS" },
26830 { qr_SCRIPT_CONTHP_IS_HEARTS, "qr_SCRIPT_CONTHP_IS_HEARTS" },
26831 { qr_MULTI_PLATFORM_FFC, "qr_MULTI_PLATFORM_FFC" },
26832 { qr_SEPARATE_BOMBABLE_TAPPING_SFX, "qr_SEPARATE_BOMBABLE_TAPPING_SFX" },
26833 { qr_BROKEN_BOMB_AMMO_COSTS, "qr_BROKEN_BOMB_AMMO_COSTS" },
26834 { qr_CONVEYORS_ALL_LAYERS, "qr_CONVEYORS_ALL_LAYERS" },
26835 { qr_OLD_BROKEN_WARPEX_MUSIC, "qr_OLD_BROKEN_WARPEX_MUSIC" },
26836 { qr_BROKEN_LIFTSWIM, "qr_BROKEN_LIFTSWIM" },
26837 { qr_BROKEN_GENERIC_PUSHBLOCK_LOCKING, "qr_BROKEN_GENERIC_PUSHBLOCK_LOCKING" },
26838 { qr_BROKEN_FLAME_ARROW_REFLECTING, "qr_BROKEN_FLAME_ARROW_REFLECTING" },
26839 { qr_EW_FIRE_EMITS_LIGHT, "qr_EW_FIRE_EMITS_LIGHT" },
26840 { qr_NEWDARK_TRANS_STACKING, "qr_NEWDARK_TRANS_STACKING" },
26841 { qr_OLD_HERO_WARP_RETSQUARE, "qr_OLD_HERO_WARP_RETSQUARE" },
26842 { qr_BROKEN_PUSHBLOCK_TOP_HALF_SOLIDS, "qr_BROKEN_PUSHBLOCK_TOP_HALF_SOLIDS" },
26843 { qr_BROKEN_PUSHBLOCK_FLAG_CLONING, "qr_BROKEN_PUSHBLOCK_FLAG_CLONING" },
26844 { qr_OLD_LANDING_SFX, "qr_OLD_LANDING_SFX" },
26845 { qr_FIRE_LEVEL_TRIGGERS_ARENT_WEAPONS, "qr_FIRE_LEVEL_TRIGGERS_ARENT_WEAPONS" },
26846 { qr_BLOCKS_DROWN, "qr_BLOCKS_DROWN" },
26847 { qr_LAYER6_STRINGS_OVER_SUBSCREEN, "qr_LAYER6_STRINGS_OVER_SUBSCREEN" },
26848 { qr_PUSHBLOCKS_FALL_IN_SIDEVIEW, "qr_PUSHBLOCKS_FALL_IN_SIDEVIEW" },
26849 { qr_BROKEN_ICY_FLOOR_SIDEVIEW, "qr_BROKEN_ICY_FLOOR_SIDEVIEW" },
26850 { qr_BROKEN_SYSTEM_COLORS, "qr_BROKEN_SYSTEM_COLORS" },
26851 { qr_WEAPONS_EXTRA_SPAWN_FRAME, "qr_WEAPONS_EXTRA_SPAWN_FRAME" },
26852 { qr_BROKEN_SCROLL_INSTEAD_OF_DROWN_FALL, "qr_BROKEN_SCROLL_INSTEAD_OF_DROWN_FALL" },
26853 { qr_LIFTED_WEAPONS_RUN_SCRIPTS, "qr_LIFTED_WEAPONS_RUN_SCRIPTS" },
26854 { qr_BOMB_BOOMS_CLEAR_SCRIPTS, "qr_BOMB_BOOMS_CLEAR_SCRIPTS" },
26855 { qr_BETTER_ENGINE_AUTOROTATE, "qr_BETTER_ENGINE_AUTOROTATE" },
26856 { qr_EW_ROCKS_HARDCODED_BREAK_ON_SOLID, "qr_EW_ROCKS_HARDCODED_BREAK_ON_SOLID" },
26857 { qr_IMPRECISE_WEAPON_SOLIDITY_CHECKS, "qr_IMPRECISE_WEAPON_SOLIDITY_CHECKS" },
26858 { qr_NO_STUNLOCK_IGNORE, "qr_NO_STUNLOCK_IGNORE" },
26859 { qr_BROKEN_BLOCKHOLE_PITFALLS, "qr_BROKEN_BLOCKHOLE_PITFALLS" },
26860 { qr_CUSTOM_WEAPON_BROKEN_SIZE, "qr_CUSTOM_WEAPON_BROKEN_SIZE" },
26861 { qr_OLD_WEAPON_REFLECTION, "qr_OLD_WEAPON_REFLECTION" },
26862 { qr_OLD_SPRITE_FALL_DROWN, "qr_OLD_SPRITE_FALL_DROWN" },
26863 { qr_OLD_TERMINAL_VELOCITY, "qr_OLD_TERMINAL_VELOCITY" },
26864 { qr_BETTER_PLAYER_JUMP_ANIM, "qr_BETTER_PLAYER_JUMP_ANIM" },
26865 { qr_ARMOS_GRAVE_ON_LAYERS, "qr_ARMOS_GRAVE_ON_LAYERS" },
26866 { qr_OLD_SCRIPT_LEVEL_GLOBAL_STATES, "qr_OLD_SCRIPT_LEVEL_GLOBAL_STATES" },
26867 { qr_BROKEN_ARMOS_GRAVE_BIGHITBOX_COLLISION, "qr_BROKEN_ARMOS_GRAVE_BIGHITBOX_COLLISION" },
26868 { qr_HERO_DIVE_UNDER_LAYER_1, "qr_HERO_DIVE_UNDER_LAYER_1" },
26869 { qr_CLASSIC_DRAWING_ORDER, "qr_CLASSIC_DRAWING_ORDER" },
26870 { qr_YSORT_SPRITES, "qr_YSORT_SPRITES" },
26871 { qr_OLD_WEAPON_DRAW_ANIMATE_TIMING, "qr_OLD_WEAPON_DRAW_ANIMATE_TIMING" },
26872 { qr_SCRIPTS_6_BIT_COLOR, "qr_SCRIPTS_6_BIT_COLOR" },
26873 { qr_BROKEN_SCRIPTS_SCROLLING_HERO_POSITION, "qr_BROKEN_SCRIPTS_SCROLLING_HERO_POSITION" },
26874 { qr_HIDE_BOTTOM_8_PIXELS, "qr_HIDE_BOTTOM_8_PIXELS" },
26875 { qr_BROKEN_SCRIPTS_BITMAP_DRAW_ORIGIN, "qr_BROKEN_SCRIPTS_BITMAP_DRAW_ORIGIN" },
26876 { qr_INVERTED_DARK_COMBO_TRIGGERS, "qr_INVERTED_DARK_COMBO_TRIGGERS" },
26877 { qr_SCRIPTS_SCREEN_DRAW_LIGHT_NO_OFFSET, "qr_SCRIPTS_SCREEN_DRAW_LIGHT_NO_OFFSET" },
26878 { qr_OLD_SCRIPTS_INTERNAL_ARRAYS_BOUND_INDEX, "qr_OLD_SCRIPTS_INTERNAL_ARRAYS_BOUND_INDEX" },
26879 { qr_OLD_SCRIPTS_ARRAYS_NON_ZERO_DEFAULT_VALUE, "qr_OLD_SCRIPTS_ARRAYS_NON_ZERO_DEFAULT_VALUE" },
26880 { qr_ROPE_ENEMIES_SPEED_NOT_CONFIGURABLE, "qr_ROPE_ENEMIES_SPEED_NOT_CONFIGURABLE" },
26881 { qr_OLD_SCRIPT_VOLUME, "qr_OLD_SCRIPT_VOLUME" },
26882 { qr_OLD_DMAP_INTRO_STRINGS, "qr_OLD_DMAP_INTRO_STRINGS" },
26883 { qr_SCRIPTDRAWSFROZENMSG, "qr_SCRIPTDRAWSFROZENMSG" },
26884 { qr_BROKEN_SIDEVIEW_SPRITE_JUMP, "qr_BROKEN_SIDEVIEW_SPRITE_JUMP" },
26885 { qr_PARSER_250DIVISION, "qr_PARSER_250DIVISION" },
26886 { qr_PARSER_NO_LOGGING, "qr_PARSER_NO_LOGGING" },
26887 { qr_PARSER_SHORT_CIRCUIT, "qr_PARSER_SHORT_CIRCUIT" },
26888 { qr_PARSER_BOOL_TRUE_DECIMAL, "qr_PARSER_BOOL_TRUE_DECIMAL" },
26889 { qr_SPRITEXY_IS_FLOAT, "qr_SPRITEXY_IS_FLOAT" },
26890 { qr_PARSER_TRUE_INT_SIZE, "qr_PARSER_TRUE_INT_SIZE" },
26891 { qr_WPNANIMFIX, "qr_WPNANIMFIX" },
26892 { qr_NOSCRIPTSDURINGSCROLL, "qr_NOSCRIPTSDURINGSCROLL" },
26893 { qr_OLDSPRITEDRAWS, "qr_OLDSPRITEDRAWS" },
26894 { qr_WEAPONSHADOWS, "qr_WEAPONSHADOWS" },
26895 { qr_ITEMSHADOWS, "qr_ITEMSHADOWS" },
26896 { qr_OLDEWPNPARENT, "qr_OLDEWPNPARENT" },
26897 { qr_OLDCREATEBITMAP_ARGS, "qr_OLDCREATEBITMAP_ARGS" },
26898 { qr_OLDQUESTMISC, "qr_OLDQUESTMISC" },
26899 { qr_PARSER_FORCE_INLINE, "qr_PARSER_FORCE_INLINE" },
26900 { qr_CLEARINITDONSCRIPTCHANGE, "qr_CLEARINITDONSCRIPTCHANGE" },
26901 { qr_NOFFCWAITDRAW, "qr_NOFFCWAITDRAW" },
26902 { qr_NOITEMWAITDRAW, "qr_NOITEMWAITDRAW" },
26903 { qr_TRACESCRIPTIDS, "qr_TRACESCRIPTIDS" },
26904 { qr_FIXDRUNKINPUTS, "qr_FIXDRUNKINPUTS" },
26905 { qr_PARSER_BINARY_32BIT, "qr_PARSER_BINARY_32BIT" },
26906 { qr_ALWAYS_DEALLOCATE_ARRAYS, "qr_ALWAYS_DEALLOCATE_ARRAYS" },
26907 { qr_ONDEATH_RUNS_AFTER_DEATH_ANIM, "qr_ONDEATH_RUNS_AFTER_DEATH_ANIM" },
26908 { qr_DISALLOW_SETTING_RAFTING, "qr_DISALLOW_SETTING_RAFTING" },
26909 { qr_WEAPONS_EXTRA_DEATH_FRAME, "qr_WEAPONS_EXTRA_DEATH_FRAME" },
26910 { qr_250WRITEEDEFSCRIPT, "qr_250WRITEEDEFSCRIPT" },
26911 { qr_SETENEMYWEAPONSPRITESONWPNCHANGE, "qr_SETENEMYWEAPONSPRITESONWPNCHANGE" },
26912 { qr_BROKENCHARINTDRAWING, "qr_BROKENCHARINTDRAWING" },
26913 { qr_WRITING_NPC_WEAPON_UNIQUE_SPRITES, "qr_WRITING_NPC_WEAPON_UNIQUE_SPRITES" },
26914 { qr_COMBOSCRIPTS_LAYER_0, "qr_COMBOSCRIPTS_LAYER_0" },
26915 { qr_COMBOSCRIPTS_LAYER_1, "qr_COMBOSCRIPTS_LAYER_1" },
26916 { qr_COMBOSCRIPTS_LAYER_2, "qr_COMBOSCRIPTS_LAYER_2" },
26917 { qr_COMBOSCRIPTS_LAYER_3, "qr_COMBOSCRIPTS_LAYER_3" },
26918 { qr_COMBOSCRIPTS_LAYER_4, "qr_COMBOSCRIPTS_LAYER_4" },
26919 { qr_COMBOSCRIPTS_LAYER_5, "qr_COMBOSCRIPTS_LAYER_5" },
26920 { qr_COMBOSCRIPTS_LAYER_6, "qr_COMBOSCRIPTS_LAYER_6" },
26921 { qr_OLD_INIT_SCRIPT_TIMING, "qr_OLD_INIT_SCRIPT_TIMING" },
26922 { qr_DO_NOT_DEALLOCATE_INIT_AND_SAVELOAD_ARRAYS, "qr_DO_NOT_DEALLOCATE_INIT_AND_SAVELOAD_ARRAYS" },
26923 { qr_BITMAP_AND_FILESYSTEM_PATHS_ALWAYS_RELATIVE, "qr_BITMAP_AND_FILESYSTEM_PATHS_ALWAYS_RELATIVE" },
26924 { qr_PARSER_STRINGSWITCH_INSENSITIVE, "qr_PARSER_STRINGSWITCH_INSENSITIVE" },
26925 { qr_OLD_SLASHNEXT_SECRETS, "qr_OLD_SLASHNEXT_SECRETS" },
26926 { qr_STEP_IS_FLOAT, "qr_STEP_IS_FLOAT" },
26927 { qr_OLDMAPDATAFLAGS, "qr_OLDMAPDATAFLAGS" },
26928 { qr_OLD_PRINTF_ARGS, "qr_OLD_PRINTF_ARGS" },
26929 { qr_PASSIVE_SUBSCRIPT_RUNS_WHEN_GAME_IS_FROZEN, "qr_PASSIVE_SUBSCRIPT_RUNS_WHEN_GAME_IS_FROZEN" },
26930 { qr_WRITE_ENTRYPOINTS_AFFECTS_HEROCLASS, "qr_WRITE_ENTRYPOINTS_AFFECTS_HEROCLASS" },
26931 { qr_LOG_INVALID_UID_LOAD, "qr_LOG_INVALID_UID_LOAD" },
26932 { qr_COMBODATA_INITD_MULT_TENK, "qr_COMBODATA_INITD_MULT_TENK" },
26933 { qr_ZS_NO_NEG_ARRAY, "qr_ZS_NO_NEG_ARRAY" },
26934 { qr_PRINTF_NO_0FILL, "qr_PRINTF_NO_0FILL" },
26935 { qr_SHIELDBUBBLE, "qr_SHIELDBUBBLE" },
26936 { qr_SETENEMYWEAPONSOUNDSONWPNCHANGE, "qr_SETENEMYWEAPONSOUNDSONWPNCHANGE" },
26937 { qr_BROKEN_CONVEYORS, "qr_BROKEN_CONVEYORS" },
26938 { qr_ZS_OLD_SUSPEND_FFC, "qr_ZS_OLD_SUSPEND_FFC" },
26939 { qr_OLD_PIT_SENSITIVITY, "qr_OLD_PIT_SENSITIVITY" },
26940 { qr_ACTIVE_SHIELD_PASSIVE_ROC_NO_SCRIPT, "qr_ACTIVE_SHIELD_PASSIVE_ROC_NO_SCRIPT" },
26941 { qr_OLD_SCRIPTS_MESSAGE_DATA_BINARY_ENCODING, "qr_OLD_SCRIPTS_MESSAGE_DATA_BINARY_ENCODING" },
26942 };
26943 static std::map<string, string> qr_compat_names = {
26944 { "qr_WEAPONS_EXTRA_FRAME", qr_const_names[qr_WEAPONS_EXTRA_DEATH_FRAME]}
26945 };
26946 GUI::ListData qrs = combinedQRList() + combinedZSRList();
26947 qrs.valsort();
26948
26949 std::ostringstream missing_qrs;
26950 qrs.filter([&](GUI::ListItem& ref)
26951 {
26952 if (!qr_const_names.contains(ref.value))
26953 missing_qrs << ref.value << " [" << ref.text << "]\n";
26954 return true;
26955 });
26956
26957 auto missing_str = missing_qrs.str();
26958 if (!missing_str.empty())
26959 {
26960 missing_str = missing_str.substr(0, missing_str.size() - 2); // trailing comma
26961 printf("error: missing qr constants!\n%s\n", missing_str.c_str());
26962 exit(1);
26963 }
26964
26965 std::ofstream file(fname);
26966 if (file.fail())
26967 {
26968 printf("error outputting file '%s'\n", fname.c_str());
26969 exit(1);
26970 }
26971
26972 file << "// Quest rules. Used to toggle legacy behavior and other quest-wide options.\n";
26973 file << "enum QR\n{\n";
26974 bool did_skip = false, first = true;
26975 const string indent = "\t";
26976 for (int q = 0; q < qr_MAX; ++q)
26977 {
26978 if (!qr_const_names.contains(q))
26979 {
26980 did_skip = true;
26981 continue; // unused
26982 }
26983 string info, name;
26984 if (qrs.hasKey(q))
26985 {
26986 auto const& ref = qrs.accessItem(q);
26987 info = ref.info;
26988 name = fmt::format("'{}'", ref.text);
26989 }
26990 else info = "@deprecated";
26991
26992 vector<string> info_lines = wrap_qr_info(info);
26993
26994 if (!name.empty())
26995 {
26996 if (info_lines.empty())
26997 info_lines.push_back(name);
26998 else
26999 {
27000 info_lines.insert(info_lines.begin(), "");
27001 info_lines.insert(info_lines.begin(), name);
27002 }
27003 }
27004
27005 bool multiline_info = info_lines.size() > 1;
27006
27007 if (multiline_info)
27008 {
27009 if (!first)
27010 file << "\n";
27011 for (string const& line : info_lines)
27012 {
27013 if (line.empty())
27014 file << indent << "//\n";
27015 else
27016 file << indent << "// " << line << "\n";
27017 }
27018 }
27019 file << indent << qr_const_names[q];
27020 if (did_skip)
27021 {
27022 file << " = ";
27023 if (!(q % 8))
27024 file << (q/8) << " * 8";
27025 else file << q;
27026 }
27027 file << ",";
27028
27029 if (multiline_info || info_lines.empty())
27030 file << "\n";
27031 else file << " // " << info_lines[0] << "\n";
27032
27033 did_skip = false;
27034 first = false;
27035 }
27036 file << indent << "qr_MAX";
27037 if (did_skip)
27038 file << " = " << qr_MAX;
27039 file << "\n};\n\n";
27040
27041 file << "// Old names for old script compat\n";
27042 for(auto [old_name, new_name] : qr_compat_names)
27043 file << "const QR " << old_name << " = " << new_name << ";\n";
27044 file << "\n";
27045 }
27046
27047